Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Clearing the clipboard.

Status
Not open for further replies.

dprayner

Programmer
Oct 14, 2002
140
US
Hi I am using the VB Editor in MS Word. I was wondering what the best way to empty the contents of the clipboard.

Thank you, DAVE
 
They maybe a easier way, but this works.

Dim ClipBoard As DataObject
Set ClipBoard = New DataObject
ClipBoard.SetText ""
ClipBoard.PutInClipboard

 
Hiya,

You can use the
Code:
DataObject
to write to and read from the Windows clipboard. You'll need to set a reference to MS Forms 2.0 in your project (use Tools > references in the VBA editor), then use code like this:

Code:
Public Sub EmptyClipBoard()
    Dim myClipboard As New DataObject
    Dim l_sText As String
    Dim l_sTest As String
    
    l_sText = "Hallo, world"
    
    myClipboard.SetText l_sText
    myClipboard.PutInClipboard
    
    myClipboard.GetFromClipboard
    l_sTest = myClipboard.GetText
    MsgBox l_sTest
    
    myClipboard.Clear
    Set myClipboard = Nothing
    
End Sub

HTH

Cheers
Nikki


Cheers
Nikki
[bat] Look, mommy, I'm flying!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top