Tom’s Tutorials For Excel: *Really* Clear the Clipboard

Tom’s Tutorials For Excel: *Really* Clear the Clipboard

The Windows Clipboard is a temporary storage area for information that you have copied or moved from one place and plan to use somewhere else. You cannot see or touch the Clipboard but you can work with it to copy, cut, paste, and clear data.

There are some 30 types of data which can be copied onto your Clipboard beyond just text and formulas, such as graphics, charts, and hyperlinks. To truly empty the Clipboard requires more than just pressing the Esc key or executing the VBA codeline Application.CutCopyMode = False.

With Windows API, this VBA macro named ClearClipboard clears all data types on your Clipboard:

Public Declare Function OpenClipboard Lib "user32" _
(ByVal hwnd As Long) As Long 
Public Declare Function CloseClipboard Lib "user32" () As Long 
Public Declare Function EmptyClipboard Lib "user32" () As Long 

Sub ClearClipboard() 
OpenClipboard (0&) 
EmptyClipboard 
CloseClipboard 
End Sub
Share Button
Posted in Tom's Tutorials for Excel
Tags: , , , , , , , , , , , ,
2 comments on “Tom’s Tutorials For Excel: *Really* Clear the Clipboard
  1. Matthew Skomal says:

    Tom, when I paste this into a module or workbook the top 3 Public Declarations are in RED, and won’t compile. Any idea why? I’ve never used a Public Declaration before, so obviously I don’t understand what I’m doing.

    • Tom Urtis says:

      The first likely suspect I would rule out is the double quote characters. On some browsers, they copy into the modules as a different double quote character than the one on our keyboard. So do this, take a close look at the code and methodically one by one, carefully delete each double quote character and in its place type in the double quote character from your keyboard. When you are sure that you have nailed every double quote character, try the code again. I know it works, so post back with how this fix attempt turns out for you.

Leave a Reply

Your email address will not be published. Required fields are marked *

*