Moustafa Mahmoud
Moustafa Mahmoud

Reputation: 43

run a macro on another workbook and then close the workbook that launched the macro

How to
1. Run macro from current (FIRST.XLSM) workbook to open another workbook(SECOND.XLSM)
2. Run Macro on (SECOND.XLSM) workbook that closes (FIRST.XLSM) and then continues its procedure I tried this:

Sub FirstMacro()
Workbooks.Open Range("f90")        'second workbook full path

Workbooks("first.XLSM").Close SaveChanges:=True  'save first workbook and close
Second_Workbook_Macro ' run second workbook macro
End Sub

But since it saves and closes the first workbook the vba doesn't continue its procedure ..

Upvotes: 2

Views: 4557

Answers (1)

Tim Williams
Tim Williams

Reputation: 166316

Sub FirstMacro()

    Dim wb As Workbook
    Set wb = Workbooks.Open Range("f90")   'second workbook full path

    Application.Run "'" & wb.Name & "'!Second_Workbook_Macro"

    ThisWorkbook.Close SaveChanges:=True  'save first workbook and close

End Sub

Upvotes: 2

Related Questions