Word

Clear the contents of the clipboard

Ease of Use

Easy

Version tested with

2000, 2003 

Submitted by:

MOS MASTER

Description:

Programmatically clear the contents of the clipboard. 

Discussion:

Your code adds a lot of data to the clipboard and to make sure the clipboard doesn?t reach its max size you can clear it to avoid errors and improve overall speed. 

Code:

instructions for use

			

Option Explicit Public Sub ClearClipBoard() Dim oData As New DataObject 'object to use the clipboard oData.SetText Text:=Empty 'Clear oData.PutInClipboard 'take in the clipboard to empty it End Sub

How to use:

  1. Open your Word document.
  2. Press Alt + F11 to open VBE.
  3. Insert-UserForm (insert -> UserForm) this is to make sure you can use the DataObject Object.
  4. Insert-Module. (Insert -> module)
  5. Paste the code there in the window at right. (F7)
  6. Close VBE (Alt + Q or press the X in the top right hand corner).
  7. Save the file.
 

Test the code:

  1. Copy something on to the clipboard.
  2. From Word, press Alt + F8 to open the macro dialog box.
  3. Select ClearClipBoard
  4. Click Run. (The clipboard will be cleared)
 

Sample File:

Clear Clipboard.zip 8.29KB 

Approved by mdmackillop


This entry has been viewed 101 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express