首页 > 解决方案 > How to save workbook to a new location without saving changes in the old one

问题描述

Is it possible to SaveAs workbook in to a new location with macros enabled(.xlsm) without having the changes saved in old one.

In example i open original workbook, create a new sheet, then macro would save it to a new location without changing original file, so if i were to open the original file again later it is without the new sheet created before. All help is much appriciated

I am using this code to save a file, but it also saves changes in the original file.

Dim path As String
Dim name As String

path = Application.ActiveWorkbook.path
name = Replace(ActiveWorkbook.name, ".xlsm", "")
Application.ActiveWorkbook.SaveAs Filename:=path & "\" & name & "_spreadcell", FileFormat:=52

My plans for future are to import sheets from another workbook and then save this new file to opened workbook location and not save changes in the original file. So if something gets messed up, the user could still use the original file again to import and create new workbook.

Best regards

标签: excelvba

解决方案


As i commented before:

That's basically what SaveAs does. It Saves File A as File B and opens File B afterwards without saving changes to File A. There's also SaveCopyAs, which saves a copy of File A as File B, but keeps File A open.


推荐阅读