我在将脚本导入UFT超过2周时遇到严重问题,我尝试了一切。作为一个worarround,我正在编写工作簿,然后我导入新的,但这有时也不起作用。 这是我的代码:
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帮助
答案 0 :(得分:1)
如果你想要它们,为什么要遍历行?只需复制表格即可。如果您需要该代码,请启动宏录制器,复制工作表并停止宏录制器。
答案 1 :(得分:0)
将您的DataTable.ImportSheet workbook1,"name1","sheet1"
来电更改为DataTable.ImportSheet workbook1,"name1","Action1"
或DataTable.ImportSheet workbook1,"name1","Global"
。确保您的工作簿路径正确,工作簿中存在 name1 工作表
答案 2 :(得分:0)