View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Print a preset group of pages

Untested, but it uses the code you posted:

Option Explicit
Sub test()
Dim VPC As Long
Dim HPC As Long
Dim HPB As HPageBreak
Dim NumPage As Long
Dim myNames As Variant
Dim iCtr As Long
Dim FoundCell As Range

myNames = Array("turner, david", "turner, kathleen")

For iCtr = LBound(myNames) To UBound(myNames)
Set FoundCell = Range("A:A").Find(What:=myNames(iCtr))
If FoundCell Is Nothing Then
MsgBox myNames(iCtr) & " wasn't found"
Else
HPC = ActiveSheet.HPageBreaks.Count + 1
VPC = 1
NumPage = 1
For Each HPB In ActiveSheet.HPageBreaks
If HPB.Location.Row ActiveCell.Row Then Exit For
NumPage = NumPage + VPC
Next HPB
Sheets(1).PrintOut From:=NumPage, To:=NumPage, Preview:=True
End If
Next iCtr
End Sub


(I changed "as integer" to "as long".)

You may want to provide all the parms to your .find statement. Excel/VBA
remembers what was used. So you may be disappointed if the user (or code) did a
..find with matchcase:=true (for example).


David wrote:

David wrote

Something like:
StudentArr=("student1","student2","student3")
L = StudentArr
For i = Lbound(L) To Ubound(L)
Application.Find (i)
Application.PrintOut what:= that page
Next i


Here's some code I found and adapted for testing for a single name:

Sub test()
Dim VPC As Integer, HPC As Integer
Dim HPB As HPageBreak
Dim NumPage As Integer
Range("A:A").Find(What:="turner, david").Activate
HPC = ActiveSheet.HPageBreaks.Count + 1
VPC = 1
NumPage = 1
For Each HPB In ActiveSheet.HPageBreaks
If HPB.Location.Row ActiveCell.Row Then Exit For
NumPage = NumPage + VPC
Next HPB
Sheets(1).PrintOut From:=NumPage, To:=NumPage, Preview:=True '<would change
to actually print
End Sub

Can someone show me how to process an array of names?
--
David


--

Dave Peterson