selectPDF文件保存位置

我很放心,终于得到了下面的代码在这个社区的帮助下工作。

在我的愿望清单中,我还有另一个select,我正在努力。 目前,下面的代码会将工作表3一直保存到名为“post”的工作表中作为单独的PDF文件到我select的文件夹中。 这是由一个形状触发的。

我试图让下面的代码提示文件夹select,以便用户可以select他们的PDF文件保存的位置,有没有人有任何想法如何做到这一点?

此外,底部的Call Shell最好打开保存文件的文件夹,但只要用户知道文件的保存位置,就不需要这么做:)

Sub SaveAllPDF() Dim i As Integer Dim Fname As String Dim TabCount As Long TabCount = Sheets("Post").Index 'Set the TabCount to the last cell you want to PDF ' Begin the loop. For i = 3 To TabCount 'Set i = the number of the first sheet you want to PDF in order from left to right To TabCount If Sheets(i).Visible <> xlSheetVisible Then Else With Sheets(i) Fname = .Range("C15") & " " & .Range("E13") & "-" & .Range("B1") 'The Fname above is equaling the cells that the PDF's filename will be 'The folder directory below is where the PDF files will be saved .ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ "C:\Users\Brandon\Desktop\operation automated\RLtemp\" & Fname, Quality:=xlQualityStandard, _ IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False End With End If Next i Call Shell("explorer.exe" & " " & "C:\Users\Brandon\Desktop\operation automated\RLtemp\", vbNormalFocus) 'This opens the folder where the PDFs are saved End Sub 

您可以使用Excel的FileDialog对象:

 Sub SaveAllPDF() Dim i As Integer Dim Fname As String Dim TabCount As Long TabCount = Sheets("Post").index 'Set the TabCount to the last cell you want to PDF Dim dialog As FileDialog Dim path As String Set dialog = Application.FileDialog(msoFileDialogFolderPicker) dialog.AllowMultiSelect = False If dialog.Show = -1 Then path = dialog.SelectedItems(1) ' Begin the loop. For i = 3 To TabCount 'Set i = the number of the first sheet you want to PDF in order from left to right To TabCount If Sheets(i).Visible <> xlSheetVisible Then Else With Sheets(i) Fname = .Range("C15") & " " & .Range("E13") & "-" & .Range("B1") 'The Fname above is equaling the cells that the PDF's filename will be 'The folder directory below is where the PDF files will be saved .ExportAsFixedFormat Type:=xlTypePDF, filename:=path & "\" & Fname, Quality:=xlQualityStandard, _ IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False End With End If Next i Call Shell("explorer.exe" & " " & path & "\", vbNormalFocus) 'This opens the folder where the PDFs are saved End If End Sub