I am using Office 365 under Windows 10, 64 bit. I am trying to clear the clipboard. The macro recorder produces an empty sub.
The following attempts are mostly collected from How to Clear Office Clipboard with VBA :
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 Sub ClearClipboardA()
Application.CutCopyMode = False
End Sub
Public Sub ClearClipBoardB()
' Source: http://www.vbaexpress.com/kb/getarticle.php?kb_id=462
Dim oData As New DataObject
oData.SetText Text:=Empty ' Clear
oData.PutInClipboard ' Putting empty text into the clipboard to empty it
End Sub
Public Sub ClearClipboardC()
OpenClipboard (0&)
EmptyClipboard
CloseClipboard
End Sub
Version A:
Method or data member not found
Version B: Runs without clearing the clipboard. A small yellow status window appears shortly:
"7 of 24 - Clipboard | Element not fetched"
(translated into English)
Version C: Nothing seems to happen.
In the above reference user iamstrained writes: “... if anyone is hunting for how to do this in Office 365 under 64-Bit, you now need to use the modifications for backwards compatibility to make this work: Private Declare PtrSafe
and LongPtr
as your two changes to these values will resolve issues and allow it to still work.”
I found a reference to a Microsoft page, where this has perhaps been done:
Using subs shown here I can insert text into the clipboard and extract from it, but not clear it.