VBA 宏中另存为位置的对话框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6948344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Dialog Box for Save As location in VBA Macro
提问by soytsauce
I'm trying to export a file as a PDF as part of a larger macro. However, I'd like the user to have the option of saving the file to a directory of his or her choosing, and I think this would be easiest with a browsing dialog box. However, I can't figure out how to pull one up. Currently, my code reads as follows.
我正在尝试将文件导出为 PDF 作为较大宏的一部分。但是,我希望用户可以选择将文件保存到他或她选择的目录中,我认为使用浏览对话框最容易。但是,我不知道如何拉起一个。目前,我的代码如下。
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\<filepath>.08E PT5 Executive Summary - v3.2.pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, From:=1, To:=3, OpenAfterPublish:=True
I'd like to replace with the result of the dialog box.
我想用对话框的结果替换。
回答by GSerg
Application.GetSaveAsFilename
.
Application.GetSaveAsFilename
.
dim v as variant
v = Application.GetSaveAsFilename("11.08E PT5 Executive Summary - v3.2.pdf", "PDF Files (*.pdf), *.pdf")
if vartype(v) = vbString then
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=v, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, From:=1, To:=3, OpenAfterPublish:=True
end if