An Excel VBA subroutine that involves interaction with the Windows Clipboard fails to run with the error: “Compile error: User-defined type not defined.” The line of code highlighted by Excel as being the cause of the error includes a reference to the “DataObject” object type.
(Tested on my machine with Excel 2003 SP3)
In the Microsoft Visual Basic editor:
- Stop debugging by clicking the “Stop” button on the toolbar (if debugging isn’t already stopped).
- Tools menu | References
- In the list of available references, find “Microsoft Forms 2.0 Object Library”, check it, and click OK. (For me, this was the 2nd unchecked item from the top of the list; it wasn’t sorted alphabetically in the list like most of the rest of the listed items.)
- Run the macro again.
That’s it! Hope this helps!