Hi there, I got this particular code from a previous post here but, as the post was from 2014 I thought it may be best to start fresh.
I have a workbook that contains around 40 sheets, and I need to PDF each of them seperately to different filepaths under different names.
The code is as follows, where R1 contains the whole filepath + target name as these both change in each sheet.
This Macro runs consistently for the first 5 sheets within the workbook before I am kicked out with the following error.
Sub SaveasPDF() ' ' SaveasPDF Macro ' ' Keyboard Shortcut: Ctrl+d ' Dim sh As Worksheet Dim fname As String Dim location As String For Each sh In Worksheets sh.Select fname = sh.Range("R1").Value ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fname & ".pdf", _ Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False fname = Empty Next End Sub
Anyone have any idea why this might be happening?
Thanks in advance.