Hi there,
I'm sure this is a simple problem to some of the geniuses on here but I don't know how to do it.
I want to be able to dynamically select the sheets for printing based on a variable, I have set these as Boolean for the time being but they could be anything as they are just generated as whether certain cells are greater than zero. So in a nutshell I have 4 variables (There will be more hence my need for the dynamic bit) that relate to whether a sheet should be included in the Sheets(array(...)).select statement at the end to save to PDF. A shortened version of what I have so far is included below, you can see that for more than 4 variables it's going to be a lot of If statements.
This is run within a loop for each salesperson and I'd like to be able to generate an array for the
Sheets(Array("Report", "Not Boughts", "Samples", "Emails", "Phone")).Select
based on whether the relevant variables are true or not, print if true.
So if only Samples is true then the array would end up
Sheets(Array("Report","Samples")).Select ( Report is the headline page and is always printed, pdf'd)
Any tips greatly appreciated
Jon
I'm sure this is a simple problem to some of the geniuses on here but I don't know how to do it.
I want to be able to dynamically select the sheets for printing based on a variable, I have set these as Boolean for the time being but they could be anything as they are just generated as whether certain cells are greater than zero. So in a nutshell I have 4 variables (There will be more hence my need for the dynamic bit) that relate to whether a sheet should be included in the Sheets(array(...)).select statement at the end to save to PDF. A shortened version of what I have so far is included below, you can see that for more than 4 variables it's going to be a lot of If statements.
Code:
Dim NotBoughts As Boolean
Dim Samples As Boolean
Dim Emails As Boolean
Dim Phone As Boolean
If NotBoughts = True And Samples = True And Emails = True And Phone = True Then
Sheets(Array("Report", "Not Boughts", "Samples", "Emails", "Phone")).Select
myfile = "M:\JonA\Secure\" & pi.Name & " WE" & Format(mydate, "ddmmyyyy") & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=myfile, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False
Else:
This is run within a loop for each salesperson and I'd like to be able to generate an array for the
Sheets(Array("Report", "Not Boughts", "Samples", "Emails", "Phone")).Select
based on whether the relevant variables are true or not, print if true.
So if only Samples is true then the array would end up
Sheets(Array("Report","Samples")).Select ( Report is the headline page and is always printed, pdf'd)
Any tips greatly appreciated
Jon