简体   繁体   中英

Excel 2007 VBA to save open workbook as backup without changing original

I am trying to adapt this code I found online

Sub SaveCopyas2()
Dim newWB As Variant
Dim wb1 As Workbook, wb2 As Workbook

Set wb1 = ActiveWorkbook
If wb1.Saved = False Then MsgBox wb1.FullName, vbInformation, "Workbook Not Saved"

 'Set a filename for new workbook
newWB = Application.GetSaveAsFilename(ActiveWorkbook.FullName, "Excel Files (*.xls), *.xls", , "Set Filename")
If newWB <> False Then wb1.SaveCopyAs (newWB)
End Sub

What this does, is it allows the user to run a macro and save a backup by specifying the location, and the name

What I am trying to do is just have it so that when the macro is run, the file is named "Backup" and the location is C:\\

Can anybody help me fix this code to do what I am looking to do?

(Answered by the OP in a question edit. Moved into a community wiki answer. See Question with no answers, but issue solved in the comments (or extended in chat) )

The OP wrote:

here is what I got to work.

Sub SaveCopyas2()
Dim newWB As Variant
Dim wb1 As Workbook
Set wb1 = ActiveWorkbook
With wb1
    .SaveCopyAs ("C:\Backup.xlsm")
End With
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