View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default Please Help Me Annotate Subroutine

Jim,

See my comments inline: the printout to a pdf should work if you have the PDF printer as your
default printer

Sub PrintJob()
Dim Sel As Boolean
Dim myS As Worksheet

'Sel is a flag for selecting the already selected sheet with the first sheet that meets the criteria
'Otherwise, the currently active sheet would be printed as well

Sel = True

'Step through the worksheets
For Each myS In Worksheets
'Check only visible (unhidden) sheets and ignore hidden sheets
If myS.Visible Then
'Check the value of cell F52 on that sheet
If myS.Range("F52").Value 0 Then
'Create the sheet grouping using the Replace parameter
'Sel is true for the first sheet, False for the rest
myS.Select Sel

'Set the replace parameter to false so that other sheets can be added
'to the collection of sheets to print
Sel = False
End If
End If
Next myS

'Print all the sheets at once
ActiveWindow.SelectedSheets.PrintOut

End Sub


HTH,
Bernie
MS Excel MVP


"RST Engineering (jw)" wrote in message
m...
.
.
Bernie ...

I saw it after I posted my question. It seems somebody hijacked my original post from a week ago
and passed it off as their own under a different Subject. I will certainly try your code.
However, it seems like your code prints sheets out one by one, doesn't it? Or does it batch print
them?

The problem with printing one by one is that when you go to "print" to a pdf file each sheet has
to be given a different file name, then you have to assemble all the pdf files into one file,
making sure that the sheets are all in order (which they rarely are).

Can you step me through your code, treating me as you would any other freshman history major?

{;-)

Jim

--
"It is the mark of an educated mind to be able to entertain a thought without accepting it."
--Aristotle


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Jim,

Did you try this code that I posted?

Sub PrintJob()
Dim Sel As Boolean
Dim myS As Worksheet

Sel = True

For Each myS In Worksheets
If myS.Visible Then
If myS.Range("F52").Value 0 Then
myS.Select Sel
Sel = False
End If
End If
Next myS

ActiveWindow.SelectedSheets.PrintOut

End Sub

HTH,
Bernie
MS Excel MVP