Visual Basic Application.GetSaveAsFilename 对话响应
这一定是最愚蠢的问题。我有以下 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该有效...
This should work ...