PDA

View Full Version : Custom Toolbar Help



vassili
08-12-2007, 02:26 PM
i'm stuck on how to link a custom toolbar button to a module within the active workbook.

so far my toolbars have been linked to active workbooks with specific names. for example, in the workbook "MAIN" i have a custom toolbar button with an assigned macro to 'MAIN.xls'!Module1.OpenExport.

now, how do i refer to this macro without pointing to the specific workbook MAIN.XLS? i'm looking for something that will point the code to look for the macro in the active workbook.

the reason is that the program will be creating copies of this "MAIN" workbook with different names. these new copies will have the module1.openexport macro in them, but i dunno how to program in the name of the new workbooks to correspond.

right now, i'm assigning macros manually by clicking that little down arrow at the end of the custom toolbar and choosing "customize"

is there a way to do this in vba?

daniel_d_n_r
08-12-2007, 02:54 PM
sorry not sure i misread your question.

[/VBA] Application.CommandBars("Custom 1").Controls.Add Type:=msoControlButton, ID _
:=2950, Before:=1[/VBA]

I recorded a macro and got this..

vassili
08-12-2007, 06:42 PM
sorry not sure i misread your question.

[/vba] Application.CommandBars("Custom 1").Controls.Add Type:=msoControlButton, ID _
:=2950, Before:=1[/vba]

I recorded a macro and got this..

i've already got the button named "ADD" created and placed in the custom toolbar "aBOM" in the new workbook.

all i did was create a copy of my original workbook named "MAIN" and saved it as an increment to the original workbook name. (i.e. "MAINx" where "x" is a digit)

however, now i have the button "ADD" in "MAINx.xls" with a macro @ address 'MAIN.xls'!Module1.OpenExport. I need it to actually point to 'MAINx.xls'!Module1.OpenExport.

so i figure it would be nice to tell the "ADD" button to always use the macro in Module1.OpenExport in the current "active" workbook so i won't have to open MAIN.xls for "ADD" to work.

i hope that makes more sense

Ken Puls
08-12-2007, 07:14 PM
If I've read this correctly, OpenExport is just a macro in a standard module within this workbook, correct? If so, you shouldn't actually need to qualify this as much as you've done.

Try this:

Call OpenExport

Providing the Sub is not prefaced as Private, I think that this should work for you.

vassili
08-12-2007, 08:34 PM
If I've read this correctly, OpenExport is just a macro in a standard module within this workbook, correct? If so, you shouldn't actually need to qualify this as much as you've done.

Try this:

Call OpenExport

Providing the Sub is not prefaced as Private, I think that this should work for you.

how can i call OpenExport though? this is a toolbar button. here's a picture to clarify things. the only way i know to change the macro of the button is by steps 1 -> 2 -> 3.

http://home.cogeco.ca/~zaitsev/button.jpg

Ken Puls
08-12-2007, 09:06 PM
Ah, okay. Didn't realize that you were picking it from the Macro box. Honestly, I've never done it that way.

Why don't you just pick "OpenExport" in the "Assign Macro" listbox?

rory
08-13-2007, 03:26 PM
Can you explain why you want to call the macro in the active workbook? If you are creating copies of a workbook, isn't the macro the same in all of them? It sounds to me as though you would be better off moving the code into an add-in and having that create the toolbar button, pointing to the macro in the add-in. Much easier than having identical copies of the code everywhere.

Bob Phillips
08-14-2007, 01:42 AM
Why not just create the toolbar in Personal.xls, and have it work on the Activeworkbook, rather than replicate it everywhere.