First post so please excuse any poor etiquette.
I am writing a VBA which produces an information pack for our customers to use. This pack is built to be dynamic based on certain user selections - for example FAQ pages will be specific to selections made by the user. I have built each module to add the relevant sheet names to a contents sheet as it runs. At the end, I pick up this list of sheets, select them and produce a PDF.
What I am trying to do is hide all of the other sheets other than the ones that are selected - I can do this by calling them specifically by name, or by adding "zzz" to the end of sheet names which are pure reference sheets, but I am hoping there is a better way.
The code I want would do this:
- Select all of the sheets which have been added to the contents page and create an array (this already works)
- Produce the PDF for the selected sheets (this also works)
- Hide any sheet which is not in the array (this is what I am struggling with)
Code for producing the PDF is below - note that due to some ill-planned naming, "Contents Array" is a named range on the contents sheet, and "ContentsList" is the VBA array:
For Each cell In wsContents.Range("ContentsArray")
ContentsList(j) = cell.Value
wb1.Sheets(cell.Value).Select
j = j + 1
Next 'cell
wb1.Sheets(ContentsList()).Select
FileName = wsControl.Range("CustomerName") & " Pack " & Format(wsControl.Range("ReportDate"), "dd-mm-yyyy")
PDFFilePath = wb1.Path & "/AutoGenerated Packs/" & FileName & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=PDFFilePath, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True