How to clear clipboard on mac excel vba

Application.CutCopyMode=False on windows excel clears the dotted line and clipboard data is lost which is desirable.

But the same is not true for Mac OS. On Mac it clears the dotted line but the clipboard data is not lost.

Is there a single line or any method which will clear the clipboard on mac and windows ?

Answers


I found this code here, I dont have or use Mac so I cannot test this out but from reading the code it will assign "" (nothing in other words) to this clipboard.

Hope this works or at least gets you on the right direction

Public Function ClearMacClipBoard() As Boolean
    Dim myDO As DataObject

    On Error GoTo EndCMCB
    Set myDO = New DataObject
    myDO.SetText ""
    myDO.PutInClipboard
    Application.CutCopyMode = False
    ClearMacClipBoard = True
EndCMCB:
    On Error GoTo 0
End Function

Edit:

Slight change from comments to try and work both on Windows and Mac

This should skip any line of code that would noramlly bug out so when you try to run Mac code on Windows it will just skip it and vise-versa

Public Function ClearMacClipBoard() As Boolean
    Dim myDO As DataObject

    On Error GoTo Resume Next
    Set myDO = New DataObject
    myDO.SetText ""
    myDO.PutInClipboard
    Application.CutCopyMode = False
    ClearMacClipBoard = True
    On Error GoTo 0
End Function

Need Your Help

api to create a new page on confluence

curl confluence jira-rest-api confluence-rest-api

I am a member of a confluence group which I open from browser from the following URL