Export to pdf in user-selected folder

dtnce

New Member
Joined
Feb 15, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
So I've got this macro to export a worksheet to a pdf and save it in a folder selected by the user:

VBA Code:
Sub pdf()

    If Range("A1").Value = "" Then GoTo err
    Dim folder As FileDialog
    Dim Fldr As String
    Set folder = Application.FileDialog(msoFileDialogFolderPicker)
    With folder
        .AllowMultiSelect = False
        If .Show <> -1 Then GoTo err
        Fldr = .SelectedItems.Item(1)
    End With
    Application.DisplayAlerts = False
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("A1").Value, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=False
    Exit Sub
err:
    MsgBox "FILE NOT SAVED - 'OK' to continue"
    Exit Sub
End Sub

My problem is, when it runs, it saves to the previous folder in the hierarchy than the one selected. If user selects the folder U:\Files\pdf\test the file is saved in U:\Files\pdf

Any thoughts are greatly appreciated
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Welcome to MrExcel forums.

You aren't including the selected folder in the file name.
VBA Code:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Fldr & "\" & Range("A1").Value, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=False
 
Upvote 0
Solution
Welcome to MrExcel forums.

You aren't including the selected folder in the file name.
VBA Code:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Fldr & "\" & Range("A1").Value, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=False
?‍♂️ Stare at something long enough and you forget to look at the obvious. Thanks for the help!
 
Upvote 0

Forum statistics

Threads
1,214,810
Messages
6,121,690
Members
449,048
Latest member
81jamesacct

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top