循环工作表的所有行并将其复制到空白表 [英] Loop all the rows of a worksheet and copy them into a blank sheet

查看:87
本文介绍了循环工作表的所有行并将其复制到空白表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将脚本导入UFT超过2个星期时,我遇到了一个严重的问题,我尝试了一切.令人担忧的是,我正在复制工作簿,然后导入新的工作簿,但这有时也行不通. 这是我的代码:

I'm facing a serious problem while importing my script into UFT for more than 2 weeks, I tried everything. As a worarround, I'm cpying the workbook and then I import the new on but this sometimes doesn't work too. this is my code:

DataTable.ImportSheet workbook1,"name1","sheet1"

这是我的工作环境:

On error resume next
DataTable.ImportSheet workbook_path,"name1","sheet1"
MsgBox "Error: " & Err.Number & " (" & Err.Source & ") - " & Err.Description

If Err.Number <> 0 Then
  If err.number = 20012 Then
Set objExcel1 = CreateObject("Excel.Application")      
objExcel1.Visible = False
objExcel1.DisplayAlerts=False

Dim RelativePath
RelativePath = "C:\xyz\new_workbook.xls"
Dim objSheet1
Set objWorkbook1= objExcel1.Workbooks.Open("workbook.xls")
Set filesys = CreateObject("Scripting.FileSystemObject") 
If filesys.FileExists(RelativePath) Then
filesys.DeleteFile RelativePath
End If 

Set objWorkbook2=objExcel1.Workbooks.Add   
objWorkbook2.saveAs RelativePath

For each objsheet1 in objworkbook1
objworkbook2.AddSheet  objsheet1.Name
objsheet1.copy objworkbook2.sheets(1)   
Next
objWorkbook2.save
objworkbook1.close
objworkbook2.close
objExcel1.Quit
Set objSheet1 = Nothing
Set objWorkbook1 = Nothing
Set objWorkbook2 = Nothing
Set objExcel1 = Nothing

On error resume next
DataTable.ImportSheet RelativePath,"name1","sheet1"
 MsgBox "Error: " & Err.Number & " (" & Err.Source & ") - " & Err.Description
End if 
End If

我想尝试循环工作表的所有行并将其复制到新的行中,而不是直接复制它们.有什么帮助吗?如果有人有其他解决方案来解决此问题,请pleeeeeeease帮助

I want to try looping all the rows of the sheets and copying them into the new ones instead of copying them directly. Any help please ? if anyone has other solution to solve this issue, pleeeeeeease help

推荐答案

为什么要遍历所有行?只需复制工作表即可.如果您需要该代码,请启动宏记录器,复制工作表并停止宏记录器.

Why loop through the rows if you want them all? Just copy the sheet. IF you need the code for that, fire up the macro recorder, copy the sheet and stop the macro recorder.

这篇关于循环工作表的所有行并将其复制到空白表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆