Auto close a workbook from closing a workbook with macro

djmelanson

New Member
Joined
Jun 3, 2015
Messages
17
Hi guys, I have two workbooks named Book1 and Hydro Line Stops. I created a macro that opens the Hydro Line Stops file automatically upon opening Book1. I have copied what I have so far below:

Private Sub Workbook_Open()
Workbooks.Open Filename:="\\bdl0fs05\Departments\Hydro Mechanical\Production Management\OE Open Order Status\Hydro Line Stops.lnk"
ThisWorkbook.Activate

End Sub

This works perfectly fine but I would like to also close the Hydro Line Stops file automatically when I close the Book1 workbook. I have tried:

Workbook("Hydro Line Stops.xlsm").close False

but I'm obviously doing something wrong here. Any help would be appreciated. Thanks.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I assume that you put this in the Workbook_BeforeClose event.

It should be "Workbooks(" not "Workbook(" but that may be a typo in the message or it could be your problem.
 
Upvote 0
This is what I put in and it still comes up with an error and the debug claims that it's the 2nd line.

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Workbooks("Hydro Line Stops.xls").Close savechanges:=False

End Sub

I'm not sure what the (cancel as Boolean) part means, I'm new to macro.
 
Upvote 0
The Cancel allows the Close to be stopped if there is an issue in the checking you are doing when they close the workbook. Say that before you allow them to close you do some validation checks and you find an issue. You can display a message and then abort the Close by setting Cancel=TRUE.

Not an issue but you should set it to FALSE just to be sure.

Are you getting any type of error message? What is happening? Is Book1 closing but "Hydro Line Stops.xls" is staying open?
 
Upvote 0
I actually changed it a bit and it seems to work. I just put

Sub Auto_Close()
Workbooks("Hydro Line Stops").Close
End Sub

and it is working just fine. Thank you for your input!
 
Upvote 0

Forum statistics

Threads
1,215,026
Messages
6,122,738
Members
449,094
Latest member
dsharae57

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