code errors

viper

Active Member
Joined
Feb 15, 2002
Messages
382
Hello all,

I'm using this code I found in my book, but when I use it I get errors of with block variable not set

Here's the code:

Code:
'Get the index of the Help menu

HelpIndex = CommandBars(1).Controls("Help").Index

'Create new control
Set NewMenu = CommandBars(1).Controls.Add(Type:=msoControlPopup, _
Before:=HelpIndex, Temporary:=True)
'add caption
NewMenu.Caption = "Fi&gures"

All I'm wanting to do is create a new control so I can then add menu items under it for my worksheet.

Is there a limit to the number of controls on the standard commandbar?

I currently have the standard items, HTML, Andrews Utilities, and ASAP Utilities.

Thanks,
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,318
Office Version
  1. 365
Platform
  1. Windows
Can you post the rest of the code?

What you have posted so far looks fine to me.
 

viper

Active Member
Joined
Feb 15, 2002
Messages
382
Then I'm assuming that's my problem. That's all my code. I don't use more than that when I add menu items to existing controls.

What else do I need.
 

viper

Active Member
Joined
Feb 15, 2002
Messages
382
Sorry, for some reason when I put the code into the Workbook_Open event it wouldn't work and had errors, when I created a separated macro and then ran that from the Workbook_Open event it is now working.
 

Forum statistics

Threads
1,147,507
Messages
5,741,566
Members
423,667
Latest member
Kai_357

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top