回答
在另一篇文章中看到了這一點,我用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
只需複製並粘貼到代碼中,您需要清除剪貼板。
我注意到的另一件事是當我編寫一個程序,比如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
我在VBA代碼中使用上述示例從Excel文件導入數據。請參閱here
此功能位於庫「Microsoft Forms 2.0 Object Library」中。要鏈接到該庫,請轉至VBA編輯器,然後選擇「工具」,「引用」,如果尚未勾選,請從列表中選取它們。
你可以用一堆WinAPI調用做更多時髦的事情,但我通常更喜歡避免這些,除非絕對必要。
此外,不要忘記DisplayAlerts屬性,它會壓制對話框 - 雖然我不知道它是否總是會產生所需的結果。
說一個簡單的
Application.CutCopyMode = False
工作您的情況,或者是這個選項不是可行?
謝謝我以前見過,但從未嘗試過。它也適用於我的應用程序。它基本上刪除了CutCopy功能,它會自動刪除剪貼板數據。 –
我喜歡這個解決方案,因爲它不需要添加對象庫的引用。 – ChrisB
這是一個適合我的解決方案。這是基於後由扎克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
一個這是您的VBA項目,用於ClearClipboard
將其清除。
- 1. 清除剪貼板?
- 2. 使用VBScript清除剪貼板
- 3. 無法使用VBA清除辦公室剪貼板
- 4. 如何清除mac上的剪貼板excel vba
- 5. 使用宏清除WorkSheet的內容而不清除剪貼板
- 6. 如何使用C清除剪貼板內容#
- 7. 如何不顯示粘貼欄/清除剪貼板?
- 8. 如何清除iPhone模擬器複製和粘貼剪貼板?
- 9. 在Android上清除剪貼板
- 10. 清除KDE上的剪貼板
- 11. 在Android中清除剪貼板數據
- 12. 清除所有剪貼板條目
- 13. WinRT清除剪貼板後臺任務
- 14. 上SGS2清除剪貼板(API 10)
- 15. 在Mac上清除剪貼板
- 16. Word VBA使用替代剪貼板
- 17. VBA宏 - 如何訪問剪貼板?
- 18. 如何清空我App.getClipboard後()剪貼板
- 19. 使用剪貼板
- 20. VBA:無剪貼板複製粘貼
- 21. 使用Sikuli或Jython清除Windows的剪貼板
- 22. 清除使用GTK LIB系統剪貼板,在C
- 23. 如何從剪貼板清除指定的格式數據?
- 24. SSMS 2008 R2 - 複製粘貼結果集後清除剪貼板
- 25. 使用VBA將剪貼板中的值粘貼到Excel中
- 26. 使用VBA(Excel)從剪貼板粘貼圖像
- 27. 如何在Go中使用剪貼板?
- 28. 如何使用AppleScript的從剪貼板
- 29. 如何在vbscript中使用剪貼板?
- 30. 如何使用Applescript顯示剪貼板
感謝你的理解,'DisplayAlerts'屬性非常適用於阻止來自Excel的警報。我認爲,如果要重複使用從Excel導入數據,在每個「循環」結尾處清除剪貼板將是有益的。 –
只需確認;該屬性在Word中也可用。我沒有檢查Word的枚舉值與Excel的屬性的比較。 – NeepNeepNeep
我在Word和Excel中使用了'DisplayAlerts',調試器很開心,所以我相信它會很好。在Word中將使用'Application.DisplayAlerts'並且對於已打開的Active Excel程序它與上面顯示的相同 –