ActiveSheet.Paste 失败的 VBA Excel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27049946/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 05:19:33  来源:igfitidea点击:

ActiveSheet.Paste Failing VBA Excel

excelvbapaste

提问by A Anderson

My VBA code is set to copy a value from one sheet (NB this value will change each time the sheet is open) and paste into a 'database' on the next available row.

我的 VBA 代码设置为从一张工作表复制一个值(注意,每次打开工作表时,此值都会更改)并粘贴到下一个可用行的“数据库”中。

Think I've got it right but the Paste method seems to fail, can anyone see why?

认为我做对了,但 Paste 方法似乎失败了,有人能明白为什么吗?

Windows("Invoice Program.xlsm").Activate
Range("B4").Select
Application.CutCopyMode = False
Selection.Copy
Workbooks.Open ("C:\Users\Invoice Database.xlsx")
Windows("Invoice Database.xlsx").Activate
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
Selection.Paste

采纳答案by bilbo_strikes_back

Dim varTemp as Variant

Windows("Invoice Program.xlsm").Activate
Range("B4").Select
varTemp = ActiveCell.Value
Workbooks.Open ("C:\Users\Invoice Database.xlsx")
Windows("Invoice Database.xlsx").Activate
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveCell = varTemp

回答by dasg7

Use ActiveSheet.Paste but in the line before use DoEvents.

使用 ActiveSheet.Paste 但在使用 DoEvents 之前的行中。

DoEvents
ActiveSheet.Paste