Forum Discussion

ksmith's avatar
ksmith
Brass Contributor
May 28, 2021
Solved

Change workbook name in multiple macros

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 s...
  • tusharm10's avatar
    May 28, 2021
    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.