Open, run macro, and close workbook from another workbook vba code

WGRoad

New Member
Joined
Apr 9, 2011
Messages
13
Hello guys,

I have this code inserted in a macro in workbook1:

Code:
Workbooks.Open ("C:\workbook2.xlsm")
    INSERT_CAFETARIA
    Workbooks("workbook2.xlsm").Close savechanges:=True

When I do run this, it opens the workbook , runs the macro, but the it goes onto reopening the workbook again, giving me a message asking if I am sure I want to reopen workbook2...

If I only put this:

Code:
Workbooks.Open ("C:\workbook2.xlsm")
Workbooks("workbook2.xlsm").Close savechanges:=True

... without the macro that runs from that workbook2, then it opens, saves and closes without a problem. There's nothing wrong with the macro, as it runs well if I directly run it from workbook2. Any thoughts on what might be the problem?

Thanks in advance.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Well, I found the problem... both macros had the same name, making it run in a loop, ence always keep asking me if I was sure I wanted to open again that workbook... solved the problem :).
 
Upvote 0
how do you close a workbook that has a name that changes? my sheet saves as date and time so I am unable to put in a specific path.
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,823
Members
452,946
Latest member
JoseDavid

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