Building an array of worksheets for printing
Instead of an array have you considered using a collection instead, something
like
Dim MySheets As Collection
Sub addsheets()
Dim wks As Worksheet
Set MySheets = New Collection
MySheets.Add Sheet1, Sheet1.Name
MySheets.Add Sheet2, Sheet2.Name
For Each wks In MySheets
MsgBox wks.Name
Next wks
End Sub
You can add to the collection based on the booleans and then traverse the
collection in exactly the same manner as the worksheets object (which is
mostly just a collection of worksheets).
--
HTH...
Jim Thomlinson
"DRK" wrote:
I have one array that I use for printing a subset of worksheets in a
workbook. Baseline array is defined as:
Sheets(Array("Cover", "AboutThisIllustration", "PolicyValuesLedger", _
"PolicyValuesLedgerGuar", _
"PolicyValuesLedgerNonGuar")).Select
Depending on various Booleans I need to add other worksheets to the above.
Inclusion of these other worksheets is dependent on Booleans.
So if BoolBSIB is TRUE, then I need to add "PolicyValuesLedgerGuarGSIB", to
the above array BEFORE I get to the "PolicyValuesLedgerGuar", _
So it should read
Sheets(Array("Cover", "AboutThisIllustration", "PolicyValuesLedger", _
"PolicyValuesLedgerGuarGSIB", _
"PolicyValuesLedgerGuar", _
"PolicyValuesLedgerNonGuar")).Select
I'm stymied on how to build up this array inside of VBA. There are three
other worksheets that may or may not get printed. How can i do this inside of
VBA?
I'd hate to brute force it by building each potential variation but...I'd
prefer a more elegant solution.
--
DRK
|