启用通过vba自动保存(不点击保存提示)

在这里输入图像说明

我怎样才能通过VBA自动select保存,而无需手动点击。 例如,我有代码select数据validation列表中的每个值,并让我到下面的阶段,但我必须单击保存每次。

我曾尝试添加:

Application.EnableEvents = True 

但是,这只是把我带到了形象的舞台上。

  Sub PDFActiveSheet() Dim ws As Worksheet Dim strPath As String Dim myFile As Variant Dim strFile As String On Error GoTo errHandler Set ws = ActiveSheet 'enter name and select folder for file ' start in current workbook folder strFile = Cells.Range("B1") & " Period " & Cells.Range("J1") strFile = ThisWorkbook.Path & "\" & strFile myFile = Application.GetSaveAsFilename _ (InitialFileName:=strFile, _ FileFilter:="PDF Files (*.pdf), *.pdf", _ Title:="Select Folder and FileName to save") If myFile <> "False" Then ws.ExportAsFixedFormat _ Type:=xlTypePDF, _ Filename:=myFile, _ Quality:=xlQualityStandard, _ IncludeDocProperties:=True, _ IgnorePrintAreas:=False, _ OpenAfterPublish:=False, _ From:=1, _ To:=2 End If exitHandler: Exit Sub errHandler: MsgBox "Could not create PDF file" Resume exitHandler End Sub 

为了避免提示:

 Sub PDFActiveSheet() Dim ws As Worksheet Dim strPath As String Dim myFile As Variant Dim strFile As String On Error GoTo errHandler Set ws = ActiveSheet 'enter name and select folder for file ' start in current workbook folder strFile = Cells.Range("B1") & " Period " & Cells.Range("J1") strFile = ThisWorkbook.Path & "\" & strFile & ".PDF" ws.ExportAsFixedFormat _ Type:=xlTypePDF, _ Filename:=strFile, _ Quality:=xlQualityStandard, _ IncludeDocProperties:=True, _ IgnorePrintAreas:=False, _ OpenAfterPublish:=False, _ From:=1, _ To:=2 exitHandler: Exit Sub errHandler: MsgBox "Could not create PDF file" Resume exitHandler End Sub