0
Set objExcel = createObject("Excel.Application")

Set objWorkbook = objExcel.Workbooks.Open("C:\Users\deven.kamlesh.jain\Desktop\abcd.xlsx")
iRow = objworkbook.sheets("Sheet1").Usedrange.rows.Count
objworkbook.Sheets("sheet1").Range("A1:C"& iRow).Copy

objExcel.visible = true
Set Obj1 = objexcel.workbooks.add()
objExcel.displayalerts = false
Obj1.saveas("Copied abcd")

Obj1.Sheets("Sheet1").Range("A1").PasteSpecial

我正在尝试将一个文件复制到另一个文件,但我收到一条错误消息,指出该类的PasteSpecial方法Range失败。

4

1 回答 1

0

PasteSpecial观察到错误而失败的原因是该SaveAs操作清除了复制的数据。在SaveAs之后移动 并在之前向右PasteSpecial移动。我还建议将一般配置属性放在应用程序对象的实例化之后或之后。CopyPasteSpecialVisibleDisplayAlerts

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.DisplayAlerts = False

Set objWorkbook = objExcel.Workbooks.Open _
  ("C:\Users\deven.kamlesh.jain\Desktop\abcd.xlsx")
Set Obj1 = objExcel.Workbooks.Add

iRow = objWorkbook.Sheets("Sheet1").UsedRange.Rows.Count
objWorkbook.Sheets("sheet1").Range("A1:C"& iRow).Copy
Obj1.Sheets("Sheet1").Range("A1").PasteSpecial

Obj1.SaveAs "Copied abcd"
于 2013-05-20T11:38:11.900 回答