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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear Clipboard

Status
Not open for further replies.

Ankor

Programmer
Mar 21, 2002
144
0
0
US
I need to clear clipboard from Excel 2003 SP1 VBA. I found couple codes that should do it, but none of them work for me.
This code returns an error message "User-defined type not defined":

Public Sub ClearClipboard()
Dim MyDataObj As New DataObject
MyDataObj.SetText ""
MyDataObj.PutInClipboard
End Sub


This code does not error, but it does not do anything either:

Declare Function CloseClipboard Lib "user32" () As Long
Declare Function EmptyClipboard Lib "user32" () As Long
Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long

Sub ClearAllClipboard()
OpenClipboard 0&
EmptyClipboard
CloseClipboard
End Sub


What am I doing wrong? Thank you for your help.
 

The first code needs a reference to the Microsoft Forms 2.0 Object Library (under Tools > References).

The second should work - I just cut and pasted it and it worked for me.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
What version of Excel do you have? Can it be a problem with Excel 2003 SP1? I have a reference to Microsoft Forms 2.0 Object Library, but I have to create a physical form to make the code run without errors. For some reason none of the codes clears the clipboard.
 

Are you wanting to clear the Windows clipboard or the Office clipboard (with the 24 items)? Both codes clear the Windows clipboard. It is not possible to clear the Office clipboard with VBA in Office 2002/2003.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
I did not even realize there are two different types of clipboard :). I think it's Office because I see the items in it when I copy/paste within Excel, and yes, there are 24 items in it.

Thank you for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top