Discussion Locked

Macro works on toolbar but not in Word

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a Word document
I have a working macro on the toolbar
I have a Visual Basic command button on the Word document
I copy the code from the tool bar to the command button
I click on the command button and get error
"User-defined type not defined"
This error relates to the code:
Dim oOutlookApp As New Outlook.Application
Thank you.

6 replies

by lord ago 1

Sounds like you're missing the declaration for that type in the button which is what causes this kind of error. The toolbar would have it but the button won't see it unless you put it into the button where needed.

Have Fun!!!

by peyison

First off - please rate the other answers I've left for you. :)

I believe this problem relates to the fact that you copied the macro from your Word document, to the "Normal" template. This is because you saved your new toolbar in Normal - so thatis where the code will exist.

In your original document you must have had a reference to the Outlook library. You need to add the same reference to Normal. To do this:

Open the VB editor (Tools -> Macros -> Visual Basic Editor)

You'll see a reference for the Normal project in the Project window. Select it.

Choose Tools -> References and check Microsoft Outlook xx Object Library.

You should be good to go.

Hope this helps.

by peyison

woops. Looks like I got it backwords. You're moving from the toolbar to a command button. You'll need to add the reference to the new Word doc that contains the command button.

This discussion is closed to new replies.