ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Assigning Macros to Toolbar buttons (https://www.excelbanter.com/excel-programming/330047-assigning-macros-toolbar-buttons.html)

VBA Fun

Assigning Macros to Toolbar buttons
 
When a file containing a macro is saved using 'save as' under a new name the
toolbar buttons are modified...the assign macro setting is changed to the new
name.

Is there a way to programatically change the assignment? If not, do you
have any suggestions on how to distribute a VBA application, where the
functions are made easily accessible through a custom toolbar, without the
risk of the assignment getting modified?

Thanks in advance,



--
VBA Fun

Greg Wilson

Assigning Macros to Toolbar buttons
 
My preference is to programmatically create the toolbar on WB_Open and to set
its Temporary property to True in order to avoid having to delete it on
WB_BeforeClose. However, I believe the standard is to have code delete it. I
also prefer to make it invisible on WB_Deactivate and visible again on
WB_Activate in order to avoid having it available if the user switches
between WB's without closing the former. Else errors may be gernerated if the
buttons get clicked while an inappropriate WB is active.

This method in affect makes custom TB's workbook based instead of
application based. To my knowledge, TB customizations reside on the drive in
which they were created (e.g. Excel.xlb) which leads to no end of pain in an
intranet environment. If the WB is saved using 'save as' then closing and
reopening the original will solve the problem.

Typically I assign the macro names, captions and tool tips to separate
arrays. I create the tool bar using a loop and apply the above by referencing
the array index values.

Regards,
Greg Wilson

"VBA Fun" wrote:

When a file containing a macro is saved using 'save as' under a new name the
toolbar buttons are modified...the assign macro setting is changed to the new
name.

Is there a way to programatically change the assignment? If not, do you
have any suggestions on how to distribute a VBA application, where the
functions are made easily accessible through a custom toolbar, without the
risk of the assignment getting modified?

Thanks in advance,



--
VBA Fun


Tom Ogilvy

Assigning Macros to Toolbar buttons
 
Just to add:

commandbars("Custom1").Controls("MyControl").OnAct ion =
"MyWorkbook.xls!MyMacro"

--
Regards,
Tom Ogilvy

"VBA Fun" .(donotspam) wrote in message
...
When a file containing a macro is saved using 'save as' under a new name

the
toolbar buttons are modified...the assign macro setting is changed to the

new
name.

Is there a way to programatically change the assignment? If not, do you
have any suggestions on how to distribute a VBA application, where the
functions are made easily accessible through a custom toolbar, without the
risk of the assignment getting modified?

Thanks in advance,



--
VBA Fun





All times are GMT +1. The time now is 05:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com