Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub CopyTabsToIndividualFiles()
- 'PURPOSE: Copy all visible tabs to individual files
- 'SOURCE: www.TheSpreadsheetGuru.com
- Dim FolderPath As String
- Dim sht As Worksheet
- 'Determine Folder Path
- FolderPath = Application.ActiveWorkbook.Path
- 'Optimize Code (Turn off)
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- 'Loop through each sheet in ActiveWorkbook
- For Each sht In ThisWorkbook.Worksheets
- 'Ensure sheet is visible so we can copy it
- If sht.Visible = xlSheetVisible Then
- 'Copy Sheet to new workbook
- sht.Copy
- DoEvents
- 'Save tab as an Excel File (use Sheet's name)
- Application.ActiveWorkbook.SaveAs Filename:=FolderPath & "\" & sht.Name & ".xlsx"
- 'Save tab as a PDF File (use Sheet's name)
- Application.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
- Filename:=FolderPath & "\" & sht.Name & ".pdf"
- 'Close File
- Application.ActiveWorkbook.Close False
- End If
- Next
- 'Optimize Code (Turn back on)
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- 'Notify user all copies have been made
- MsgBox "All sheets have been saved to individual files"
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement