是否有可能使保存button(不保存为button)将文档保存在特定的path?
我想在VBA excel中为我的validation程序做保存button。
保存button将文件保存在一个spesicicpath中并自动重命名为文档的状态(清除或错误)。
如果文件仍然保存错误,文件将被命名为error.xlsm
但是,当我修复文档的错误。 该文件将被命名为clean.xlsm。 我很讨厌手动删除第一个文件(error.xlsm)。
有没有可能使保存button保存(不保存为button)保存文件在特定的path,而不使用另存为?
这是我的代码:
Private Sub CommandButton2_Click() ActiveWorkbook.SaveAs Filename:="D:\" & Sheets("C").Range("G23").Text & ".xlsm", _ FileFormat:=xlOpenXMLWorkbookMacroEnabled, Password:=vbNullString, WriteResPassword:=vbNullString, _ ReadOnlyRecommended:=False, CreateBackup:=False ActiveWorkbook.Close End Sub
*注意: Sheets("C").Range("G23").Text
包含文档的状态(如果公式是干净的或者错误的)
试试这个…
Private Sub CommandButton2_Click() Dim fName As String Application.DisplayAlerts = False fName = ActiveWorkbook.Sheets("C").Range("G23").Value ActiveWorkbook.SaveAs FileName:="D:\" & fName & ".xlsm", _ FileFormat:=xlOpenXMLWorkbookMacroEnabled, Password:=vbNullString, WriteResPassword:=vbNullString, _ ReadOnlyRecommended:=False, CreateBackup:=False ActiveWorkbook.Close On Error Resume Next Select Case fName Case "Error" Kill "D:\Clean.xlsm" Case "Clean" Kill "D:\Error.xlsm" End Select End Sub