vba Excel 2007 宏在 2010 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9334071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel 2007 Macro does not work in 2010
提问by Bob Hausler
This macro worked just fine before we updated to windows 7 and Excel 2010. The macro stops at Activesheet.paste. All this does is open a file, copy the data and paste it to the first document. There is more code at the end to close all the open documents. Thanks, Bob
在我们更新到 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
采纳答案by Jerry Beaucaire
Use of SELECT and ACTIVATE is cumbersome, you should be able to set variables references to your worksheet(s) and do copy commands directly with no selecting.
使用 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
To paste values, separate the copy/paste to separate commands:
要粘贴值,请将复制/粘贴分隔为单独的命令:
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