pawtech

X_SaveSelectedSheetsSaveAsPDF

Dec 2nd, 2020 (edited)
4,321
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub SaveSelectedSheetsSaveAsPDF()
  2. 'Create a PDF of each selected sheet in the same folder
  3.  
  4. Dim ws As Worksheet
  5. Dim sheetArray As Variant
  6. Dim Path As String
  7. Path = Application.ActiveWorkbook.Path
  8.  
  9. 'Capture the selected sheets
  10. Set sheetArray = ActiveWindow.SelectedSheets
  11.  
  12. 'Loop through each selected worksheet
  13. For Each ws In sheetArray
  14.  
  15. ws.Select
  16.     ws.ExportAsFixedFormat Type:=xlTypePDF, _
  17.     Filename:=Path & "\" & ws.Name & ".pdf", Quality:=xlQualityStandard, _
  18.         IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
  19.  
  20. Next ws
  21.  
  22. 'Reselect the selected sheets
  23. sheetArray.Select
  24.  
  25. End Sub
RAW Paste Data