Home

MacOffice

General XL tips

This site will look better if you upgrade to a browser that supports web standards.

This site will look better if you upgrade to a browser that supports web standards.

Clearing the Mac clipboard from Excel

In Windows XL versions, calling Application.CutCopyMode = False will clear the XL clipboard (which is ideosyncratic to XL in that certain operations clear the clipboard automatically, and some don't, without a whole lot of predictability).

The Mac clipboard, however, is persistent - when you set the CutCopyMode to False in MacXL, the "marching ants" border surrounding the copied cell(s) goes away, but the contents are retained on the clipboard. This can cause occasional problems when trying to limit the user's ability to copy and paste data.

ClearMacClipBoard()

If you need to clear the clipboard from XL, you can do so using a DataObject that contains a null string. This function will clear the clipboard and set the CutCopyMode to False:

    Public Function ClearMacClipBoard() As Boolean
        'Clear the Mac Clipboard - J.E. McGimpsey
        'http:www.mcgimpsey.com/macoffice/excel/clearclipboard.html
        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

Call this as with any function from VBA. A return value of True will indicate that the clipboard is clear.

Valid XHTML 1.1Valid CSSMade on a Macintosh

Quick Links

Unfamiliar with macros? See David McRitchie's Getting Started With Macros and User Defined Functions