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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,029
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
L

Legacy 287389

Guest
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

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,029
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
L

Legacy 287389

Guest
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

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,344
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
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
L

Legacy 287389

Guest
RoryA,

thank you...I will certainly look at all my options, will give you feedback a bit later on...thanx again..
 
Upvote 0

Forum statistics

Threads
1,190,600
Messages
5,981,871
Members
439,741
Latest member
mblacklock

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