简体   繁体   中英

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 ..

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM