PDA

View Full Version : Close and save changes in one workbook from another.



donwb
06-04-2021, 03:27 AM
I have 2 workbooks A & B.
With B open, I add data to a worksheet.
Then when I open A, I need it to close B and save the changes I've made to B.
What code can I add to A & B do this, and where should it be located.

mana
06-05-2021, 07:17 PM
Paste the code in ThisWorkbook module


Private Sub Workbook_Open()
Dim wb As Workbook

On Error Resume Next
Set wb = Workbooks("B.xlsx")
On Error GoTo 0

If Not wb Is Nothing Then
wb.Close Not wb.Saved
End If

End Sub