PDA

View Full Version : Save worksheet as pdf using cell value and loop through work sheets



ashanker
02-01-2017, 03:20 PM
Hi I am currently using this macro to save the active worksheet as a pdf using a cell value as the file name. I have 8 different workbooks and some with up to 60 work sheets. I am wanting to get the macro to loop from my active worksheet to the last one in the work book. Any help is very appreciated.
Sub PDF()
Dim SaveAsStr As String

SaveAsStr = ActiveWorkbook.Path & "\" & ActiveSheet.Range("l8").Value

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=SaveAsStr & ".pdf", _
OpenAfterPublish:=False
End Sub

Kenneth Hobs
02-01-2017, 04:55 PM
Welcome to the forum! Please paste code between code tags. Click # on toolbar to insert tags.


Sub PDF()
Dim SaveAsStr$, i&

For i = ActiveSheet.Index To Worksheets.Count
With Worksheets(i)
SaveAsStr = ActiveWorkbook.Path & "\" & .Range("l8").Value
.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=SaveAsStr & ".pdf", _
OpenAfterPublish:=False
End With
Next i
End Sub