ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro names in a Module (https://www.excelbanter.com/excel-programming/335472-macro-names-module.html)

[email protected]

Macro names in a Module
 
I've found that assigning a macro to a toolbar control employs the
filename as a prefix to the macro name. EX: myfile.xls!macro1. If the
workbook is renamed or a copy made with a different name, the controls
will continue to look for the macro in the original file. Is there any
way to limit the assigned name to the macro name only?


Tom Ogilvy

Macro names in a Module
 
No, I believe not. part of the name is the location.

That said, I have never tried

something.OnAction = "!Macro1"

but I think that would prepend a name as well.

--
Regards,
Tom Ogilvy




wrote in message
oups.com...
I've found that assigning a macro to a toolbar control employs the
filename as a prefix to the macro name. EX: myfile.xls!macro1. If the
workbook is renamed or a copy made with a different name, the controls
will continue to look for the macro in the original file. Is there any
way to limit the assigned name to the macro name only?




Michel Pierron

Macro names in a Module
 
Simply:
ThisWorkbook.Name & "!macro1"

MP

a écrit dans le message de news:
...
I've found that assigning a macro to a toolbar control employs the
filename as a prefix to the macro name. EX: myfile.xls!macro1. If the
workbook is renamed or a copy made with a different name, the controls
will continue to look for the macro in the original file. Is there any
way to limit the assigned name to the macro name only?




STEVE BELL

Macro names in a Module
 
Another approach is to have the workbook create the control either on an
existing toolbar or a new toolbar when the workbook opens (and delete it
when the workbook closes)

Remember to add a delete to remove it all before you remake it.
Or check to see if it already exists before you remake it.

--
steveB

Remove "AYN" from email to respond
"Michel Pierron" wrote in message
...
Simply:
ThisWorkbook.Name & "!macro1"

MP

a écrit dans le message de news:
...
I've found that assigning a macro to a toolbar control employs the
filename as a prefix to the macro name. EX: myfile.xls!macro1. If the
workbook is renamed or a copy made with a different name, the controls
will continue to look for the macro in the original file. Is there any
way to limit the assigned name to the macro name only?






excelgurudummy[_2_]

Macro names in a Module
 

I once new a Steve Bell in Florida - any chance you're him

--
excelgurudumm
-----------------------------------------------------------------------
excelgurudummy's Profile: http://www.excelforum.com/member.php...fo&userid=2544
View this thread: http://www.excelforum.com/showthread.php?threadid=38998


STEVE BELL

Macro names in a Module
 
I have family down there, but never lived there.

I originated in Washington, DC and am now in Oregon...

--
steveB

Remove "AYN" from email to respond
"excelgurudummy"
wrote in
message news:excelgurudummy.1ss5j5_1122387049.767@excelfor um-nospam.com...

I once new a Steve Bell in Florida - any chance you're him?


--
excelgurudummy
------------------------------------------------------------------------
excelgurudummy's Profile:
http://www.excelforum.com/member.php...o&userid=25441
View this thread: http://www.excelforum.com/showthread...hreadid=389983




[email protected]

Macro names in a Module
 
I've tried this suggestion and it doesn't work. Other than substituting
single quotes for doubles in your suggestion, I've entered it exactly
as shown. When I access the button afterwards, the full directory path
has been added to " 'ThisWorkbook.Name&'!macro1". I've also tried
variations such as " 'ThisWorkbook.Name'!macro1 " as well as
subsituting the worksheet for "Name". Activating the control always
indicates "can't find macro". Any ideas what I'm doing wrong?


[email protected]

Macro names in a Module
 
Okay, I finally got it! Part of the problem was that I was trying to
make the assignment Michael suggest from outside of Visual Basic. Not
gonna work!! Here's what I finally did.
I had already created an auto_open macro for something else. But
defining the button macros there works great. For each button on the
custom toolbar called "SBIC" I added a line like the following to
assign a Module-level macro.

CommandBars("SBIC").Controls("Vendor Order").OnAction = _
ThisWorkbook.Name & "!VendorOrder"

Now, changing the filename has no negative impact upon locating macros.

thanks for all the help. It's much appreciated.



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

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