VBA“保存到PDF”甚至可以保存取消

时间:2015-07-06 14:25:59

标签: vba excel-vba pdf excel

我的宏有问题。我想避免宏保存PDF文件,即使我按下保存对话框中的取消 。我错过了什么?

以下是代码:

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

现在它不再起作用了,它说不可能保存PDF。

1 个答案:

答案 0 :(得分:2)

myFile <> "False"

应该是

myFile <> False

ref