The following code creates folders in the current file path based on a cell reference for each worksheet in a workbook and then saves the worksheet to the folder by the same name. I have been trying unsuccessfully to export each worksheet as a pdf instead of saving it as an excel file. I am an admitted novice. Any advice is to modify the code is much appreciated; or do I need to start over for what I'm trying to achieve?
Public Sub TESTSaveShtsToPDF()
Dim Sheet As Worksheet, SheetName$, MyFilePath$, N&
Dim theFilePath As String
MyFilePath$ = ActiveWorkbook.Path & ""
For Each Sheet In ActiveWorkbook.Worksheets
SheetName$ = Sheet.Range("c3").Value
With Application
.ScreenUpdating = False
.DisplayAlerts = False
' End With
On Error Resume Next '<< a folder exists
theFilePath = MyFilePath & SheetName
MkDir theFilePath
With Sheet
.Select
.Copy
ActiveWorkbook.SaveAs Filename:=theFilePath & "" & SheetName & ".xlsx", FileFormat _
:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close
End With
.CutCopyMode = False
End With
Next Sheet
End Sub
Public Sub TESTSaveShtsToPDF()
Dim Sheet As Worksheet, SheetName$, MyFilePath$, N&
Dim theFilePath As String
MyFilePath$ = ActiveWorkbook.Path & ""
For Each Sheet In ActiveWorkbook.Worksheets
SheetName$ = Sheet.Range("c3").Value
With Application
.ScreenUpdating = False
.DisplayAlerts = False
' End With
On Error Resume Next '<< a folder exists
theFilePath = MyFilePath & SheetName
MkDir theFilePath
With Sheet
.Select
.Copy
ActiveWorkbook.SaveAs Filename:=theFilePath & "" & SheetName & ".xlsx", FileFormat _
:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close
End With
.CutCopyMode = False
End With
Next Sheet
End Sub