Unable to Run Code on Specific workbook



I got some great help here last night, so I thought I'd try again. I'm
creating a custom menu for a 29 worksheet template. I can run the following
code on new workbooks, but I can run it on the one that I need, the template.

Sub Auto_Open()
Dim HelpIndex As Integer
Dim NewMenu As CommandBarPopup

' Get Index of Help menu
HelpIndex = CommandBars(1).Controls("Help").Index

' Create the control
Set NewMenu = CommandBars(1) _
.Controls.Add(Type:=msoControlPopup, _
Before:=HelpIndex, Temporary:=True)
' Add a caption
NewMenu.Caption = "&Custom Menu"
End Sub

I get the following error:

Compile error:
User-Defined Type Not Defined

And it highlights the following line:

NewMenu As CommandBarPopup

Does anyone have any idea of why it doesn't work on this particluar workbook?
Any comments are appreciated.


Chip Pearson

Ensure that you have a reference (VBA Tools menu, References) to
"Microsoft Office Object Library" and that no reference is marked


It looks like the whole references & additional controls menu items are
missing (they appear but are dimmed).
Is there any way to add them back in this workbook?


I was mistaken in the previous post.
The Microsoft Office Object Library that Chip mentioned, did not have a
check mark next to it. I added the check mark and the code seems to run with
no problems.
Thanks a lot Chip! Great forum with very smart people.
Thanks again!


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question