Thanks for input. Menu not created in code. I manually asemble the menu and assign the macro's using the "Customize toolbar" functions.
Main Topics
Browse All TopicsI built some macros for Excel, and build a custom toolbar menu to call them from. This works fine. I then save the workbook with a new file name. When I try to run the macros again, it tries to call them from the file with the prior file name. I tried putting the macros in the "this workbook" section of the VBA project, but that didn't help (plus, I didn't know how to, and therefore did not, move the globals there.)
Is there a way to automagically have the custom macro menu point to the current file, even if it has been re-named?
Thanks!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi codequest,
Okay, fooled around with this a bit, and you're quite right. If you create a toolbar by just adding buttons and assigning macros, it makes it workbook specific. Save it, and they still refer to the old book. Curiously, though, if you make a menu through the same manner, they will transport just fine. Go figure that.
Personally, I prefer to create all my menus and toolbars automagically via code. I've posted some code below, which will add a button to a toolbar via code on the fly when a workbook is activated, and removes it when you activate another workbook. The code below adds a button to the Standard Toolbar, but you can easily use a different toolbar (by changing that name) or even create your very own. The benefits of this approach is that you don't have to worry about toolbars becomming corrupted, and you can ensure that they always look exactly as you want.
Here's the code:
***
Option Explicit
Private Sub Workbook_Deactivate()
'To delete a toolbar button when workbook is deactivate
Call DeleteButton
End Sub
Sub Workbook_Activate()
'To add a toolbar button to a menu when workbook is activated
Dim cb As CommandBar
Dim sCBarName As String
Dim sCaption As String
Dim sMacroName As String
'Set MenuBar, Button Caption and Macro here
sCBarName = "Standard"
sCaption = "Test Macro"
sMacroName = "Test"
'Delete any instance of the button that already exists
Call DeleteButton
'Link to commandbar
Set cb = Application.CommandBars(sC
'Add button
With cb
With .Controls.Add(Type:=msoCon
.Style = msoComboLabel
.FaceId = 59 'Change button image here
.OnAction = sMacroName
.Caption = sCaption
End With
End With
End Sub
Sub DeleteButton()
'To delete a toolbar button
Dim cbc As CommandBarControl
Dim lControl As Long
Dim sCBarName As String
Dim sCaption As String
'Set Menu Bar Name here
sCBarName = "Standard"
sCaption = "Test Macro"
'Ignore errors
On Error Resume Next
'Check each control on the toolbar and delete it if the caption matches
For lControl = Application.CommandBars(sC
Set cbc = Application.CommandBars(sC
If cbc.Caption = "Test Macro" Then
cbc.Delete
End If
Next lControl
'Resume error handling
On Error GoTo 0
End Sub
Sub test()
'Illustration purposes only
MsgBox "test"
End Sub
***
The first two procedures go in the ThisWorkbook module, and the other two go in a standard module. Remember that when you change the menu names, you must change them in both the Workbook_Activate AND the DeleteButton procedures.
HTH,
Business Accounts
Answer for Membership
by: kenpulsPosted on 2005-10-25 at 13:58:16ID: 15157914
I think it might depend on how you're calling the macros. Can you post the code that you're using to create the custom toolbar menu?