开发者

Visual Basic Application.GetSaveAsFilename dialogue response

开发者 https://www.devze.com 2023-03-07 14:12 出处:网络
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.

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 ...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号