Consulting

Results 1 to 2 of 2

Thread: Close and save changes in one workbook from another.

  1. #1
    VBAX Newbie
    Joined
    Jun 2021
    Posts
    1
    Location

    Close and save changes in one workbook from another.

    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.

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •