jtc*_*e08 11
会很简单
Application.CutCopyMode = False
Run Code Online (Sandbox Code Playgroud)
为你的情况工作,或者这个选项不可行?
Jea*_*zen 10
在另一篇文章中看到了这个,我用Word VBA测试了它.
'Clearing the Office Clipboard
Dim oData As New DataObject 'object to use the clipboard
oData.SetText text:=Empty 'Clear
oData.PutInClipboard 'take in the clipboard to empty it
Run Code Online (Sandbox Code Playgroud)
只需复制并粘贴到您需要清除剪贴板的代码中.
我注意到的另一件事是,当我.Quit是一个程序,比如Excel时,它一直在问我是否要保持数据是剪贴板.解决方法是使用上述代码清除剪贴板.见下文:
'Clearing the Office Clipboard
Dim oData As New DataObject 'object to use the clipboard
oData.SetText text:=Empty 'Clear
oData.PutInClipboard 'take in the clipboard to empty it
'You can also just remove the Alert Messages from the Excel Program while
'the code is running
'Remove alert Messages from the Excel Program when closing
ExcelProgram.DisplayAlerts = False
'Quiting the Excel Application
ExcelProgram.Quit
Run Code Online (Sandbox Code Playgroud)
我在VBA代码中使用上面的示例从Excel文件导入数据.看到这里
这是一个对我有用的解决方案。这是基于 Zack Barresse 在VBAexpress.com上发表的一篇文章:
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function EmptyClipboard Lib "user32" () As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Public Sub ClearClipboard()
OpenClipboard (0&)
EmptyClipboard
CloseClipboard
End Sub
Run Code Online (Sandbox Code Playgroud)
将此函数复制到您的 VBA 项目后,使用ClearClipboard来清除它。