Excel VBA Clear Clipboard

Written by

Editorial Team

Reviewed by

Steve Rynearson

Last updated on July 19, 2021

Excel VBA Clear Clipboard

Clearing the clipboard in Excel VBA only requires a single line of code:

Application.CutCopyMode = False

 

vba clear clipboard

However, this is different from the standard Windows clipboard.  To clear the Windows clipboard you can use the EmptyClipboard Function.  Copy and paste the code below into a code module and run Sub TestClipboardClear to clear the Windows clipboard.

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 Function ClearClipboard()
  OpenClipboard (0&)
  EmptyClipboard
  CloseClipboard
End Function

Sub TestClipboardClear()
  Call ClearClipboard
End Sub

 

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as


Learn More!
vba-free-addin

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples