How to use VBA SaveAs without closing calling workbook?

后端 未结 5 566
谎友^
谎友^ 2020-11-27 23:44

I want to:

  • Do data manipulation using a Template workbook
  • Save a copy of this work book as .xlsx (SaveCopyAs doesn\'t let you change filetypes, otherw
5条回答
  •  粉色の甜心
    2020-11-27 23:58

    Another option (only tested on latest versions of excel).

    The Macros are not deleted until the workbook is closed after a SaveAs .xlsx so you can do two SaveAs in quick succession without closing the workbook.

    ActiveWorkbook.SaveAs FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False, ConflictResolution:=xlLocalSessionChanges
    Application.DisplayAlerts = True
    

    Note: you need to turn off the DisplayAlerts to avoid getting the warning that the workbook already exists on the second save.

提交回复
热议问题