I'm trying to print to pdf using vba. However, when using the below sub I get an error subscript out of range. Could someone please let me know how to fix. Much appreciated.
Sub Print_Int()
ThisWorkbook.Worksheets(Array("Sheet16", "Sheet10")).ExportAsFixedFormat Type:=xlTypePDF
End Sub
The error means that the workbook running the code does not contain one or both of the specified sheets.
Also,
ThisWorkbook.Worksheets(Array("Sheet16", "Sheet10"))returns a Sheets object. However, ExportAsFixedFormat requires a Worksheet object.And you're missing the filename for the second argument (unless it's intentional). Try the following instead...