Close workbook in different instance

L

Legacy 287389

Guest
Hi good people!,

I use this code to open a workbook in another instance:
Code:
Dim appXL As New Excel.Application
    
    appXL.Workbooks.Open "G:\All Users\Jurie\Test\Hotel Maintenance V1SE.xlsm", IgnoreReadOnlyRecommended:=True

Now, when I close the child workbook, I would like the parent workbook to close as well. I have tried this, but it does not work:
Code:
Workbooks.Close "G:\All Users\Jurie\Test\Hotel Maintenance V1SE.xlsm"

Wrong number of arguments or invalid property assignment

Please someone help me out here?...thanx a lot!
 
Last edited by a moderator:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Not sure I understand the parent-child part in the context of 2 separate Excel instances but maybe you meant:
Code:
Workbooks("Hotel Maintenance V1SE.xlsm").Close
Hi good people!,

I use this code to open a workbook in another instance:
Code:
Dim appXL As New Excel.Application
    
    appXL.Workbooks.Open "G:\All Users\Jurie\Test\Hotel Maintenance V1SE.xlsm", IgnoreReadOnlyRecommended:=True

Now, when I close the child workbook, I would like the parent workbook to close as well. I have tried this, but it does not work:
Code:
Workbooks.Close "G:\All Users\Jurie\Test\Hotel Maintenance V1SE.xlsm"



Please someone help me out here?...thanx a lot!
 
Upvote 0
tusharm,

the method you gave will not close the workbook because it is in another instance. I do need to add the workbook path..which I did. The OPen wb works well, but not the close wb?
 
Upvote 0
I relied on your attempt at closing the workbook, which did not include a reference to the other instance. ;)

So, try,

Code:
appXL.Workbooks("Hotel Maintenance V1SE.xlsm").Close
tusharm,

the method you gave will not close the workbook because it is in another instance. I do need to add the workbook path..which I did. The OPen wb works well, but not the close wb?
 
Upvote 0
Good day Tusharm,

I was away for the holidays...thanx for the feedback..I THINK I tried what you suggested and had some problem, just cannot remember exactly now. I will however check it out again...thanx a lot..
 
Upvote 0
I would suggest you use a workbook variable to make life easier

Code:
Dim wb as workbook
set wb = appXL.Workbooks.Open("G:\All Users\Jurie\Test\Hotel Maintenance V1SE.xlsm", IgnoreReadOnlyRecommended:=True)
' other code
...

wb.Close
 
Upvote 0
RoryA,

thank you...I will certainly look at all my options, will give you feedback a bit later on...thanx again..
 
Upvote 0
I believe the issue is how the variable is defined. instead of using the defined ":appXL", use the source in the code "Excel.Application"

Excel.Application.Workbooks("Hotel Maintenance V1SE.xlsm").Close
 
Upvote 0
I believe the issue is how the variable is defined. instead of using the defined ":appXL", use the source in the code "Excel.Application"

Excel.Application.Workbooks("Hotel Maintenance V1SE.xlsm").Close
seems this only works if the other instance is already open before starting the macro...
 
Upvote 0

Forum statistics

Threads
1,214,571
Messages
6,120,302
Members
448,954
Latest member
EmmeEnne1979

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