Visual Basic Application.GetSaveAsFilename dialogue response
This must be the daftest question. I have the following VB code that pop's up a dialogue to save a PDF file when a button is hit.
It works fine, only I just realised that it executes the SAVE FILE even when the cancel button is being hit, which is bizarre unless of course I must handle the cancel event myself?
How would I go about that? what return codes do I have to check?
Sub SavePDF()
Dim PDFName As String
PDFName = ThisWorkbook.Name
PDFName = Left(PDFName, Len(PDFName)开发者_如何学编程 - 5)
PDFName = PDFName & ".pdf"
FullFileName = Application.GetSaveAsFilename(PDFName, _
"PDF(*.pdf),*.pdf*", 1, "Save As PDF File")
'check return code only executing the following when the Save Button is proessed
'HOW DO I DO THIS?
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
PDFName, Quality:=xlQualityStandard, _
IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
End Sub
Edit the day after post: Still no answer to this - surely you can test the buttons in VB????!!
If FullFileName = False
Exit Sub
End If
This should work ...
精彩评论