【发布时间】:2023-04-10 17:42:01
【问题描述】:
问题定义:在下面的 Excel VBA 示例代码 sn-p(参见清单 1)中,它旨在将单元格“A1”的内容复制粘贴到单元格“A2”,行:
Application.Calculation = xlCalculationManual
看似擦除剪贴板内存,导致运行时错误。此外,以下任何类似的语句都会产生相同的效果:
Application.Calculation = xlManual
Application.Calculation = xlAutomatic
清单 1。
'demo Sub demonstrating Clipboard Memory flash by the statement
'Application.Calculation = xlCalculationManual
Sub CopyPaste()
'select cell with some test value
Range("A1").Select
'selected value is copied to Clipboard memory
Selection.Copy
'This statement seemingly erases Clipboard memory
'causing Run-Time Error 1004
'if this line is commented-off, the procedure will run normally
Application.Calculation = xlCalculationManual
' test if clipboard is empty ---------------------
On Error Resume Next
ActiveSheet.Paste
If Err Then MsgBox "Error num: " & Err.Number & "|Clipboard is Empty": Err.Clear
'-------------------------------------------------
'target cell to copy value from Clipboard
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues
End Sub
如果您注释掉上述声明,程序将完美运行。
问题:Application.Calculation = xlCalculationManual 语句是否会刷新剪贴板内存,如果是,为什么?
任何对 Microsoft Excel 文档的引用将不胜感激。
【问题讨论】:
标签: excel clipboard copy-paste worksheet-function vba