[英]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:\\ 我正在尝试做的就是拥有它,以便在运行宏时,文件名为“ Backup”,位置为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) ) (由OP在问题编辑中回答。移至社区Wiki答案。请参阅无答案的问题,但问题已在注释中解决(或扩展为聊天) )
The OP wrote: OP写道:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.