SOLVED

Change workbook name in multiple macros

Brass Contributor

when I create a new workbook from an existing, in which there are multiple macros that refer to the original workbook, Can a macro be written that will change the workbook name in all of the macros so that they will work with the new, without having to change each one manually?

2 Replies
best response confirmed by allyreckerman (Microsoft)
Solution
1. You should look into how to share code as an add-in. That way, there's no proliferation of your code. If you want to fix a bug or enhance a code, you only have to worry about the code in the add-in. If, on the other hand, you are sharing code in a XLSM, there's no way you can find all the workbooks that contain your code, let alone fix all of them.
2. If you must stay with the current architecture, look at VBA objects ThisWorkbook and ActiveWorkbook. When you use those constructs your code will be independent of the name of the workbook containing it as well as independent of the workbook the user is currently working with.
thanks for the quick answer for above question.
this may be over my head as I am not to great with VBA but s-l-o-w-l-y learning the basics. Is there a tutorial that you could recommend for VBA?
1 best response

Accepted Solutions
best response confirmed by allyreckerman (Microsoft)
Solution
1. You should look into how to share code as an add-in. That way, there's no proliferation of your code. If you want to fix a bug or enhance a code, you only have to worry about the code in the add-in. If, on the other hand, you are sharing code in a XLSM, there's no way you can find all the workbooks that contain your code, let alone fix all of them.
2. If you must stay with the current architecture, look at VBA objects ThisWorkbook and ActiveWorkbook. When you use those constructs your code will be independent of the name of the workbook containing it as well as independent of the workbook the user is currently working with.

View solution in original post