这段代码将遍历工作簿中的所有工作表,并将每个工作表保存为单独的PDF文件。请确保在运行代码之前备份你的工作簿,以防万一。当你需要将工作表批量转换为PDF文件时,你可以使用以下示例代码作为参考。 Sub ConvertSheetsToPDF() Dim ws As Worksheet Dim wb As Workbook Dim savePath As String ' 设置保存PDF文件的路径 savePath = "C:\Users\Administrator\Desktop\PDFs\" ' 循环遍历所有工作簿 For Each wb In Workbooks ' 循环遍历工作簿中的所有工作表 For Each ws In wb.Worksheets ' 生成PDF文件名(使用工作表名) pdfFileName = savePath & ws.Name & ".pdf" ' 将工作表保存为PDF文件 ws.ExportAsFixedFormat _ Type:=xlTypePDF, _ Filename:=pdfFileName, _ Quality:=xlQualityStandard, _ IncludeDocProperties:=True, _ IgnorePrintAreas:=False, _ OpenAfterPublish:=False Next ws Next wb End Sub