Excel 2007宏在2010年不起作用

时间:2012-02-17 19:20:53

标签: excel vba excel-vba ms-office

在我们更新到Windows 7和Excel 2010之前,此宏工作正常。 宏停在Activesheet.paste。所有这一切都是打开一个文件,复制数据并将其粘贴到第一个文档。最后有更多代码可以关闭所有打开的文档。谢谢,鲍勃

Application.Goto Reference:="R7C14"
Workbooks.Open Filename:="ALSP.xls"
Workbooks("ALSP.xls").Activate
Range("B7:L61").Select
Application.CutCopyMode = False
Selection.Copy
Windows("R4SP.xls").Activate
ActiveSheet.Paste

1 个答案:

答案 0 :(得分:1)

使用SELECT和ACTIVATE很麻烦,您应该能够设置对工作表的变量引用,并直接复制命令而不进行选择。

Dim ws As Worksheet, wbREF As Workbook

Set ws = ActiveSheet
Set wbREF = Workbooks.Open("ALSP.xls")      'you may want to put the full path here

Range("B7:L61").Copy ws.Range("N7")         'copy to original sheet

wbREF.Close False                           'close the opened workbook, return to ws

要粘贴值,请将复制/粘贴分隔为单独的命令:

Set wbREF = Workbooks.Open("GASP.xls")      'you may want to put the full path here

Range("B7:L61").Copy 
ws.Range("AL7").PasteSpecial xlPasteValues  'copy to original sheet
wbREF.Close False