Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Clear Office Clipboard with VBA

Tags:

ms-word

vba

How would you clear the Microsoft Office Clipboard using VBA, specifically Word VBA?

I am copying a lot of data at time into the clipboard and don't want excessive data kept in the Clipboard.

like image 449
Jean-Pierre Oosthuizen Avatar asked Sep 23 '15 10:09

Jean-Pierre Oosthuizen


People also ask

How do I automatically clear clipboard in Excel?

Click the Home tab at the top of the window. Click the small button at the bottom-right corner of the Clipboard section of the ribbon. Click the Clear All button if you want to clear everything.

How do I clear Powerpoint clipboard?

In the Clipboard task pane, do one of the following: To clear one item, click the arrow next to the item that you want to delete, and then click Delete. To clear all items, click Clear All.


2 Answers

Would a simple

Application.CutCopyMode = False

work for your situation, or is this option not viable?

like image 67
jtchase08 Avatar answered Sep 30 '22 18:09

jtchase08


Saw this on another post, and I have tested it with Word VBA.

'Clearing the Office Clipboard

    Dim oData   As New DataObject 'object to use the clipboard

    oData.SetText text:=Empty 'Clear
    oData.PutInClipboard 'take in the clipboard to empty it

Just copy and paste into your code where ever you need to clear the Clipboard.

Another thing I noticed is that when I .Quit a program, say Excel, it keeps asking me if I want to keep the data is the Clipboard. A work around is to clear the clipboard using the above stated code. See below:

'Clearing the Office Clipboard

    Dim oData   As New DataObject 'object to use the clipboard

    oData.SetText text:=Empty 'Clear
    oData.PutInClipboard 'take in the clipboard to empty it


'You can also just remove the Alert Messages from the Excel Program while    
'the code is running
'Remove alert Messages from the Excel Program when closing
ExcelProgram.DisplayAlerts = False   

'Quiting the Excel Application
ExcelProgram.Quit

I used the above example in a VBA code to import data from an Excel File. See here

like image 24
Jean-Pierre Oosthuizen Avatar answered Sep 30 '22 17:09

Jean-Pierre Oosthuizen