Excel VBA Clear Clipboard
Excel VBA Clear Clipboard
Clearing the clipboard in Excel VBA only requires a single line of code:
Application.CutCopyMode = False
However, this is different from the standard Windows clipboard. To clear the Windows clipboard you can use the EmptyClipboard Function. Copy and paste the code below into a code module and run Sub TestClipboardClear to clear the Windows clipboard.
Option Explicit
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 Function ClearClipboard()
OpenClipboard (0&)
EmptyClipboard
CloseClipboard
End Function
Sub TestClipboardClear()
Call ClearClipboard
End Sub