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?
 

Some videos you may like

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
621
Office Version
  1. 2016
Platform
  1. Windows
Try right click on button. Re-assign the macro. It should refer to current workbook
 

TomaszM

New Member
Joined
Jan 14, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
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?
 

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
621
Office Version
  1. 2016
Platform
  1. Windows
I meant delete current one and assigned new. You need to do only once. and it will stay.
 

TomaszM

New Member
Joined
Jan 14, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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.
 

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
621
Office Version
  1. 2016
Platform
  1. Windows
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?
 

TomaszM

New Member
Joined
Jan 14, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Just copy file in explorer or similar - in the fastest way
 

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
621
Office Version
  1. 2016
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,440
Messages
5,601,680
Members
414,466
Latest member
Jools23

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
Top