我写了下面的代码,但我仍然遇到问题。该代码仅生成随机表的 pdf 版本。(五十次)此外,由于某种原因,即使定义了范围,代码也会陷入无限循环。你有什么建议吗?
Dim Folder_path As String
Dim sh As Worksheet
Dim filename As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select the folder path"
.InitialFileName = ThisWorkbook.Path
'You must manually add the location; otherwise, it will be the same as workbooks.
If .Show = -1 Then
Folder_path = .SelectedItems(1)
Else
MsgBox "No selection has been made"
Exit Sub
End If
End With
'Processes each worksheet and generates a pdf version of the sheet. Any sheets that are blank will be skipped.
For Each sh In ThisWorkbook.Worksheets
For i = 3 To 52
filename = Worksheets("Master").Cells(i, 1).Value
sh.ExportAsFixedFormat xlTypePDF, Folder_path & Application.PathSeparator & filename & ".pdf"
Next i
'On Error Resume Next
Next
End Sub```