Visual Basic Application.GetSaveAsFilename 对话响应

发布于 2024-11-09 03:20:32 字数 753 浏览 0 评论 0原文

这一定是最愚蠢的问题。我有以下 VB 代码,当按下按钮时,会弹出一个对话框来保存 PDF 文件。

它工作正常,只是我刚刚意识到即使按下取消按钮它也会执行保存文件,这很奇怪,除非我必须自己处理取消事件?

我该怎么办呢?我必须检查哪些返回码?

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

发帖后第二天编辑: 仍然没有答案 - 你当然可以在 VB 中测试按钮???!!

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????!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月亮邮递员 2024-11-16 03:20:32
If FullFileName = False
    Exit Sub
End If

这应该有效...

If FullFileName = False
    Exit Sub
End If

This should work ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文