Macro assigned to the button(Form control) doesn't work in copied file with new name

TomaszM

New Member
Joined
Jan 14, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hello,
I wrote a macro which should work internally in the file.
This file is copied (as a file) to the new one every week.
I noticed a problem, that my macro in the new (copied) file is references to the previous (original) file. It opens previous file and starts working.
I see that in the window Assign macro - there is automatically a path of file and then the macro name.

1610697306467.png

In my example the name of macro is: "KasujeKomentarze_3".

When I remove the path and click OK, it will be saved
1610697471988.png

but when I come back here again - the path is still visible
1610697597199.png


When I run macro in copied file from button, it open the previous Macro and run, not in this file.
When I run macro from the VB - it works properly in actual file.
In the code I used not direct reference like ThisWorkbook.Name.
What I'm doing wrong then?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try right click on button. Re-assign the macro. It should refer to current workbook
 
Upvote 0
Yes, I'm sure this will help, but I have 3 parallel macros in 7 sheets, so it's not comfortable. How to manage it other way?
 
Upvote 0
I meant delete current one and assigned new. You need to do only once. and it will stay.
 
Upvote 0
Yes, but as I mentioned - I make new file every week - so your solution is to change the reference in all 7 sheets - 3 macros - so 21 changes. I think there should be a faster way.
 
Upvote 0
Yes, but as I mentioned - I make new file every week - so your solution is to change the reference in all 7 sheets - 3 macros - so 21 changes. I think there should be a faster way.
I thought it is only once. How you copy it? Copy worksheet and then copy macro to another workbook?
 
Upvote 0
Just copy file in explorer or similar - in the fastest way
 
Upvote 0
Do you really need to copy each time because of previous data? If not, why not just save the original as template and reuse it. Will not have such problem
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

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