I'm new at coding. I have put together a code to save several worksheets to a pdf file and it is working except I can't figure out how to have it let me pick the filename and path. As it is it just overwrites the previously saved file.
TIA
Public Sub SaveSheetsAsPDF()
Dim wksAllSheets As Variant
Dim wksSheet1 As Worksheet
Dim strFilename As String, strFilepath As String
Dim dlgFolder As FileDialog
'Set references
Set wksSheet1 = ThisWorkbook.Sheets("TimeEnter")
wksAllSheets = Array("TimePrint", "ExpPrint", "MilesPrint")
'Set path
Set dlgFolder = Application.FileDialog(msoFileDialogFolderPicker)
With dlgFolder
.Title = "Select Target Folder Containing Mandate Files"
.AllowMultiSelect = False
If .Show <> -1 Then Exit Sub
strFilepath = .SelectedItems(1) & ""
End With
'Create the full Filename using indicated cells
With wksSheet1
strFilename = strFilepath & .Range("A3").Value & " " & .Range("B3").Value & ".pdf"
End With
' Make the sheets visible
ThisWorkbook.Sheets("TimePrint").Visible = xlSheetVisible
ThisWorkbook.Sheets("ExpPrint").Visible = xlSheetVisible
ThisWorkbook.Sheets("MilesPrint").Visible = xlSheetVisible
' Select the sheets
ThisWorkbook.Sheets(wksAllSheets).Select
'Save the array of worksheets as a PDF
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=PdfFilename, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
Worksheets("MilesEnter").Range("ClearMIles").ClearContents
Worksheets("TimeEnter").Range("ClearTime").ClearContents
Worksheets("ExpEnter").Range("ClearExp").ClearContents
'Deselect all the exported worksheets
' Hide the exported sheets
ThisWorkbook.Sheets(wksAllSheets).Visible = xlSheetHidden
End Sub
TIA
Public Sub SaveSheetsAsPDF()
Dim wksAllSheets As Variant
Dim wksSheet1 As Worksheet
Dim strFilename As String, strFilepath As String
Dim dlgFolder As FileDialog
'Set references
Set wksSheet1 = ThisWorkbook.Sheets("TimeEnter")
wksAllSheets = Array("TimePrint", "ExpPrint", "MilesPrint")
'Set path
Set dlgFolder = Application.FileDialog(msoFileDialogFolderPicker)
With dlgFolder
.Title = "Select Target Folder Containing Mandate Files"
.AllowMultiSelect = False
If .Show <> -1 Then Exit Sub
strFilepath = .SelectedItems(1) & ""
End With
'Create the full Filename using indicated cells
With wksSheet1
strFilename = strFilepath & .Range("A3").Value & " " & .Range("B3").Value & ".pdf"
End With
' Make the sheets visible
ThisWorkbook.Sheets("TimePrint").Visible = xlSheetVisible
ThisWorkbook.Sheets("ExpPrint").Visible = xlSheetVisible
ThisWorkbook.Sheets("MilesPrint").Visible = xlSheetVisible
' Select the sheets
ThisWorkbook.Sheets(wksAllSheets).Select
'Save the array of worksheets as a PDF
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=PdfFilename, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
Worksheets("MilesEnter").Range("ClearMIles").ClearContents
Worksheets("TimeEnter").Range("ClearTime").ClearContents
Worksheets("ExpEnter").Range("ClearExp").ClearContents
'Deselect all the exported worksheets
' Hide the exported sheets
ThisWorkbook.Sheets(wksAllSheets).Visible = xlSheetHidden
End Sub