|
' 如果找到了开始和结束的sheet页,则合并为单独的PDF文档 If StartSheet > 0 And EndSheet > 0 Then ' 新建一个工作簿,依次复制开始和结束之间的sheet页 Set newWb = Workbooks.Add For i = StartSheet To EndSheet wb.Sheets(i).Copy Before:=newWb.Sheets(newWb.Sheets.Count) newWb.Sheets(newWb.Sheets.Count).PageSetup.FitToPagesWide = 1 newWb.Sheets(newWb.Sheets.Count).PageSetup.FitToPagesTall = 1 Next i ' 将新工作簿保存为PDF文档,文件名以原文件名命名 newWb.ExportAsFixedFormat _ Type:=xlTypePDF, _ Filename:=FolderPath & Left(FileName, Len(FileName) - 5) & ".pdf", _ Quality:=xlQualityStandard, _ IncludeDocProperties:=True, _ IgnorePrintAreas:=False, _ OpenAfterPublish:=False ' 关闭新建的工作簿,不保存 newWb.Close SaveChanges:=False Else |
|