It has been drilled into my head, to avoid bugs and provide a good user experience, it is best to avoid using .Select
, .Activate
, ActiveSheet
,ActiveCell
, etc.
Keeping this in mind, is there a way to use the .ExportAsFixedFormat
method on a subset of Sheets
in a workbook without employing one of the above? So far the only ways I have been able to come up with to do this are to either:
- use a
For Each
; however, this results in separate PDF files, which is no good. use the code similar to that generated by the macro recorder, which uses
.Select
andActiveSheet
:Sheets(Array("Sheet1", "Chart1", "Sheet2", "Chart2")).Select ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ "exported file.pdf", Quality:=xlQualityStandard, _ IncludeDocProperties:=True, IgnorePrintAreas:=False, openafterpublish:= True
Perhaps it is impossible not to use ActiveSheet
, but can I at least get around using .Select
somehow?
I have tried this:
Sheets(Array("Sheet1", "Chart1", "Sheet2","Chart2")).ExportAsFixedFormatType:= _
xlTypePDF, Filename:= "exported file.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, openafterpublish:= _
True
This produces:
See Question&Answers more detail:oserror 438: Object doesn't support this property or method