Toolbar & dynamic filename

S

Steven

Hi,

I've got a self-made toolbar attached to a file. The
problem is that this file is saved with a different name
every time it is closed. This results in loss of the link
to the macros. Because the file is used on different
computers also, a personal workbook doesnt fulfill my
needs.
Maybe someone knows some code to attach the toolbar to the
file when it is closed (in the workbook_close event or
something like that) in such a way that it is normally
usable with the new filename again?

Thanks,

Steven
 
G

Greg Koppel

Hello Steven,

All that is needed is that you assign/unassign the macros when opening or
closing the workbook. See the code below for an example of a 2-button
toolbar.

Sub Auto_open()
Toolbars("LogForm").Visible = True
Toolbars("LogForm").ToolbarButtons(1).OnAction = "PhoneLogger"
Toolbars("LogForm").ToolbarButtons(2).OnAction = "LateLogger"
End Sub
Sub Auto_close()
On Error Resume Next
Toolbars("LogForm").ToolbarButtons(1).OnAction = ""
Toolbars("LogForm").ToolbarButtons(2).OnAction = ""
Toolbars("LogForm").Visible = False

Toolbars("LogForm").Delete
On Error GoTo 0
End Sub

HTH, Greg
 
Top