没有确认,另存为按钮

时间:2015-02-23 23:06:47

标签: vba excel-vba excel

嘿,我正在尝试制作另存为按钮的问题。它应始终保存在具有相同名称且未经确认的相同路径下。这是我到目前为止所获得的代码:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.EnableEvents = False

 Dim vFile
 Dim strDirectoryPath As String
  If SaveAsUI Then
vFile = Application.GetSaveAsFilename("C:\temp\Sample.xlsm", "Excel files (*.xlsm),*.xlsm")
If TypeName(vFile) = "Boolean" Then
 Cancel = True
 Application.EnableEvents = True
   Exit Sub  ' user cancelled
End If
strDirectoryPath = "C:\temp\"
If Dir(strDirectoryPath, vbDirectory) = "" Then MkDir strDirectoryPath

 ActiveWorkbook.SaveAs vFile, FileFormat:=56
 Application.EnableEvents = True
 saveProcessStarted = False
 Cancel = True
 Exit Sub
End If
Application.EnableEvents = True
End Sub

1 个答案:

答案 0 :(得分:0)

我想您在保存工作簿时不希望看到任何对话框。

尝试使用以下代码:

Application.DisplayAlerts = False 
ActiveWorkbook.SaveAs vFile, FileFormat:=56
Application.DisplayAlerts = True