Monday, February 2, 2015

microsoft excel - How to default Macros to run from This Workbook, NOT All Open Workbooks?


We have a macro enabled workbook (ver. 2010) that many people use. A few of these people have macros in their Personal.xlsb workbook. We have a situation where the macro in the shared workbook is named the same as a macro in personal workbooks but does slightly different things.


To avoid running the wrong macro, I'd like to default the shared workbook to run macros from This Workbook instead of All Open Workbooks. I expect to place something in WorkBook_Open(), but what?


Is there a way to change the default option for Macros in: All Open Workbooks to This Workbook?


Answer



If I rename the modules that hold the subroutines, I can specify exactly which sub to call.


Example:

In Modlue1, renamed to LocalModule1, I have:


Sub TestDupe()
Call LocalModule1.DuplicateName
End Sub
Public Sub DuplicateName()
ActiveSheet.UsedRange
MsgBox ("new mod 1")
End Sub

In Module2, renamed to be LocalModule2, I have


Public Sub DuplicateName()
ActiveSheet.UsedRange
MsgBox ("mod 2")
End Sub

By changing the qualifier in the call from LocalModule1 to LocalModule2, I can now dictate which same-named subroutine to execute.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...