How to Clear Office Clipboard with VBA

后端 未结 4 471
自闭症患者
自闭症患者 2020-12-06 07:46

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

4条回答
  •  無奈伤痛
    2020-12-06 07:58

    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

提交回复
热议问题