So I've got this macro to export a worksheet to a pdf and save it in a folder selected by the user:
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
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