0
votes

When I open Workbook 1.xlsm, Workbook 2.xls will open automatically but hidden in the background.

How do i adjust my macro so that when I close Workbook 1.xlsm, both instances of Excel will all close. i.e. Hit the close button on Workbook 1.xlsm will also close Workbook 2.xls completely.

Also, if i can save and close Workbook 2.xls, that would be great.

My code:

Private Sub Workbook_Open()

Application.ScreenUpdating = False
Workbooks.Open Filename:="\....\2016\Current BSL, Branch Stock, Whouse Stock, On Order.xls", UpdateLinks:=False, ReadOnly:=True
ActiveWindow.Visible = False
Application.ScreenUpdating = True

End Sub
1

1 Answers

0
votes

In the ThisWorkbook module, you can use the Workbook_BeforeClose procedure to close Workbook_2.xls before Workbook_1 closes.

We pass True into the .Close method so that it saves the workbook before closing it.

Private Sub Workbook_BeforeClose(Cancel As Boolean)

    Workbooks("Workbook_2.xls").Close True

End Sub