简体   繁体   中英

Dialog Box for Save As location in VBA Macro

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.

ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "C:\Users\<filepath>\11.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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM