groverparkgeorge
New Member
- Joined
- Aug 25, 2005
- Messages
- 33
I am automating Excel from Access. We open an Excel Template, populate one or more worksheets with data from the database and then save the Excel Template as a PDF.
I can make it all work smoothly as long as I hard-code the worksheets to be included in the PDF:
.Worksheets(Array("Bat-1", "Bat-2", "Bat-3", "Bat-4", "Bat-5")).Select
.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
ReportFiles & "\" & StrEquipmentTested & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
However, there may be anywhere from 1 to 9 bats in any test run, so I need to select a variable number of worksheets, one for each Bat (we're talking sports equipment, not mammals).
I can create a variable that seems to be the equivalent of the string in the Array() for selecting sheets to include, but it fails with a subscript out of range error.
Is my only alternative a Case Select that counts worksheets and uses a hard-coded set of statements?
Thanks in advance.
George
I can make it all work smoothly as long as I hard-code the worksheets to be included in the PDF:
.Worksheets(Array("Bat-1", "Bat-2", "Bat-3", "Bat-4", "Bat-5")).Select
.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
ReportFiles & "\" & StrEquipmentTested & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
However, there may be anywhere from 1 to 9 bats in any test run, so I need to select a variable number of worksheets, one for each Bat (we're talking sports equipment, not mammals).
I can create a variable that seems to be the equivalent of the string in the Array() for selecting sheets to include, but it fails with a subscript out of range error.
Is my only alternative a Case Select that counts worksheets and uses a hard-coded set of statements?
Thanks in advance.
George