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

Clipboard - DataObject type not defined 3

Status
Not open for further replies.

HiAspire

Technical User
Oct 17, 2002
10
I'm trying to do something pretty simple but am getting an error. I just want to turn the contents of the clipboard into a string variable that I can use in my Word macro application. I found this sample code below in a few places but when I run it, I get an error: "Compile error: User-defined type not defined"


Sub ClipboardTest()

Dim MyData As DataObject
Dim strClip As String

Set MyData = New DataObject
MyData.GetFromClipboard
strClip = MyData.GetText

End Sub


I'm not sure if there is something else I need to turn on in the References, or if there is an easier way to accomplish this and avoid the error I am getting. Thanks!
 
When in the VBA editor, Click Tools/References from the menu and then report back to tell us what is checked.
 
I spent an hour or two once trying to use the clipboard from Excel, unsuccessfully. If anyone has an example that actually works, I'd love to see it. My challenge was that my application needed to copy information between sheets. I was trying to preserve the clipboard contents, to not interfere with the user's operations, but wasn't successful.
Rob
[flowerface]
 
Rob: This works fine for me in Excel 97 just the way HiAspire posted it (with the addition of the MsgBox):
Code:
Sub ClipboardTest()
Dim MyData As DataObject
Dim strClip As String
  Set MyData = New DataObject
  MyData.GetFromClipboard
  strClip = MyData.GetText
  MsgBox strClip
End Sub
The only references I have checked are:
x Visual Basic for Applications
x Microsoft Excel 8. Object Library
x Microsoft Forms 2.0 Object Library

Anything else we should be looking at?
 
Can you get it to work for you in Word, though? That's where I need to be doing this.

I don't really know my way around the References area too well or what everything in there means specifically. Usually only go in there when sample codes instruct certain things be turned on. When that sample code for turning the clipboard into a string variable wasn't working in Word for me, I assumed something wasn't turned on on my side so I looked through references and checked off most things that seemed related to data objects since that was the line it didn't seem to like. When one didn't work, I clicked on the next thing that seemed related to data. Currently clicked on Visual Basic for Applications, Microsoft Word 9.0 Object Library, OLE automation, MS Office 9.0 object lib, MS DAO 3.6 Obj lib, MS ADO ext 2.7, MS Data Sources Interfaces, MS Data Access Components Installed version, MS Data formatting object library.
 
I get the exact same error in Excel 2000 on my PC.

All I have turned on in Excel under References is Visual Basic for Applications, MS Excel 9.0 Object Library, OLE automation, and MS Office 9.0 Object Library. I'm not sure what the deal is or why this seemingly simple task has become so frustrating.
 
The only one I see that I have checked and you did not list is

Microsoft Forms 2.0 Object Library

located in C:\WINDOWS\SYSTEM\FM20.DLL

You might try checking that one and see if it's the missing piece of the puzzle.
 
x Microsoft Forms 2.0 Object Library

That's the one I was missing! I'll play around a little bit with this...
Rob
[flowerface]
 
I noticed that was the one I was missing too from our lists, but didn't even see it in my list in References to add. Glad you posted where it was located. Mine was in C:/Windows/System32/FM20.DLL

When I browsed and added it into my References, it worked! Thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top