macros“保存为PDF”甚至可以保存取消
正如在标题中,我有一个macros的问题。 我想避免macros保存pdf文件,即使我按Save as
对话框中的Cancel
。 我错过了什么?
代码如下:
Sub PDFActiveSheet() Dim ws As Worksheet Dim strPath As String Dim myFile As Variant Dim strFile As String On Error GoTo errHandler Set ws = Foglio5 'enter name and select folder for file ' start in current workbook folder strFile = Replace(Replace(Foglio5.Cells(14, 2) & "_" & (Foglio5.Cells(14, 4) & "_" & (Foglio5.Cells(15, 10))), "", ""), ".", "_") _ & "_" _ & Format(Foglio5.Cells(17, 5), "yyyymmdd\") _ & ".pdf" 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 MsgBox "PDF Creato! Si trova nella cartella di questo file." End If exitHandler: Exit Sub errHandler: MsgBox "Errore nella creazione del PDF" Resume exitHandler End Sub
换行
If myFile <> "False" Then
成
If myFile Then
说明:
你声明(正确) myFile
为Variant
。 这种types将在必要时切换variables的实际types。 因此,在按下OK之后,例程返回一个String
types的值(包含path)并按下取消一个Boolean
types的Boolean
(包含False
)。