Excel VBA Command to Clear the Clipboard

When using copy and paste in a macro it is a good idea to clear the clipboard at the end of the macro. If you don’t, the user could use paste to paste the last thing you had copied in the macro.

Luckily it is easy to clear the clipboard. It’s a one line command


Usually you place this command near the end of your macro. You can also include it after each paste in your code to make sure the clipboard is cleared between each copy and paste.

If you use error handling code you would place the command with all the code to run when the macro finishes.

Note: (Added 5 November 2018) The command above clears Excel’s clipboard, but it won’t clear the clipboard inside the VBA window itself eg if you copy text inside the VBA window it is unaffected by the above code. See comments below about how to clear that clipboard by Trina McLaren. Note it is unusual to create VBA code to affect the VBA window – I have done it once in about 20 years of VBA coding.

Please note: I reserve the right to delete comments that are offensive or off-topic.