From Personal.xlsb, set .onaction macro to a macro in a worksheet in a differert workbook.

ijourneaux

New Member
Joined
Jul 9, 2018
Messages
38
From personal.xlsb, I am trying to create a button in the calling workbook and assign a macro that exists in one of the worksheet in the calling workbook.

All of the combinations I have don't produce a macro that is correctly defined. I thought this was going to work since this is exactly how the macro is listed when you browse the assign macro dialog.

.OnAction = "'" & Workbooks(WorkbookName).Worksheets("CenterLine 2").CodeName & "'" & "!CenterLine2Auto_Button_Click"

I expected this
Sheet4.CenterLine2Auto_Button_Click

but got this
'C:\Users\userid\drive\Documents\Sheet4'!CenterLine2Auto_Button_Click

that doesn't work.

I tried
.OnAction = "'" & WorkbookName & "'" & "!CenterLine2Auto_Button_Click"
whicc gave this

'Process Monitor ver4.xlsm'!CenterLine2Auto_Button_Click

but that did not work either.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Is there a reason the macro is in a worksheet code module rather than a normal module where it would seem to belong?
 
Upvote 0
Good question and I don't have a good answer. Why is a regular code module the correct place and when would you use the worksheet module?
 
Upvote 0
Generally speaking, in my opinion, code in a worksheet module would only be event code or a routine that is specific to, and only called from code in, that worksheet. Code that needs to be called from more than one place, or from the macros dialog or shapes, should be in a normal module.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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
Back
Top