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, otherwise this would be great)
- Continue showing original template (not the "saved as" one)
Using SaveAs
does exactly what is expected - it saves the workbook while removing the macros and presents me the view of the newly created SavedAs workbook.
This unfortunately means:
- I no longer am viewing my macro enabled workbook unless I reopen it
- Code execution stops at this point because
- Any macro changes are discarded if I forget to save (note: for a production environment this is ok, but, for development, it's a huge pain)
Is there a way I can do this?
'current code
Application.DisplayAlerts = False
templateWb.SaveAs FileName:=savePath, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
templateWb.Activate
Application.DisplayAlerts = True
'I don't really want to make something like this work (this fails, anyways)
Dim myTempStr As String
myTempStr = ThisWorkbook.Path & "" & ThisWorkbook.Name
ThisWorkbook.Save
templateWb.SaveAs FileName:=savePath, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close
Workbooks.Open (myTempStr)
'I want to do something like:
templateWb.SaveCopyAs FileName:=savePath, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False 'SaveCopyAs only takes one argument, that being FileName
Also note while SaveCopyAs
will let me save it as a different type (ie templateWb.SaveCopyAs FileName:="myXlsx.xlsx"
) this gives an error when opening it because it now has an invalid file format.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…