M
Mable
Alright, I've asked quite a few questions on my quest to
figure this VB thing out, but I'm completely stumped now.
What I'm trying to do is create a solution for print-tray
issue. The QC people want to automate the process of
sorting documents that need to be printed on different
types of paper, between trays 1 and 2 of an HP 5, for
documents that go up into the 200 page range.
My solution was to insert a white colored 1 or 2 at the
beginning of each page (there's a universal "first-line
blank" margin for the documents) that the macro could find
and sort accordingly.
So I've set up the following macro to search for white-
colored characters, and depending upon the results, send
the page to tray 1 or tray 2.
However, when it searches, it finds either the entire
document (which is all black) or it finds nothing. In a
seperate test environment, where I had two blank pages and
a white 1 on the top of page 1 and a white 2 on the top of
page 2, it found both characters and all of the space in
between and then still didn't process the sorting portion.
I know this code is incomplete (for example, if it were to
work right now it'd just send the entire document to each
print tray until it was done searching) but basically what
I need to know is this: Why doesn't it search one object
at a time? Why doesn't it find the '1' at the top of page
one, process, and then search for the '2' ? I suspect it
has something to do with my coding in of the myRange
object.
Code:
Sub SortPrintTrays()
'Gets page count
Dim intPages As Integer
intPages = ActiveDocument.BuiltInDocumentProperties
(wdPropertyPages)
'Creates placeholder for White characters
Dim trayMarker As Integer
'Creates variable for the entire document
Dim myRange As Range
Documents("Document1").Activate
Set myRange = ThisDocument.Content
'Test Message
MsgBox "This document contains " & Documents.Count & "
pages."
'Sorting FOR Loop, finds each White character and prints
page accordingly'
For Sort = 1 To intPages
With myRange.Find
.Forward = True
.Font.Color = wdColorWhite
.Execute
If .Found = True Then
GoTo out
End If
End With
GoTo startover
'This is the part where it sends the Job to tray 1 or 2,
depending upon the FIND results
out:
MsgBox ("Found " & myRange)
If myRange = "1" Then
MsgBox ("Printing to Tray 1!")
Options.DefaultTrayID = wdPrinterUpperBin
ActiveDocument.PrintOut
Else
MsgBox ("Printing to Tray 2!")
Options.DefaultTrayID = wdPrinterLowerBin
ActiveDocument.PrintOut
End If
startover:
Next Sort
End Sub
Thanks.
figure this VB thing out, but I'm completely stumped now.
What I'm trying to do is create a solution for print-tray
issue. The QC people want to automate the process of
sorting documents that need to be printed on different
types of paper, between trays 1 and 2 of an HP 5, for
documents that go up into the 200 page range.
My solution was to insert a white colored 1 or 2 at the
beginning of each page (there's a universal "first-line
blank" margin for the documents) that the macro could find
and sort accordingly.
So I've set up the following macro to search for white-
colored characters, and depending upon the results, send
the page to tray 1 or tray 2.
However, when it searches, it finds either the entire
document (which is all black) or it finds nothing. In a
seperate test environment, where I had two blank pages and
a white 1 on the top of page 1 and a white 2 on the top of
page 2, it found both characters and all of the space in
between and then still didn't process the sorting portion.
I know this code is incomplete (for example, if it were to
work right now it'd just send the entire document to each
print tray until it was done searching) but basically what
I need to know is this: Why doesn't it search one object
at a time? Why doesn't it find the '1' at the top of page
one, process, and then search for the '2' ? I suspect it
has something to do with my coding in of the myRange
object.
Code:
Sub SortPrintTrays()
'Gets page count
Dim intPages As Integer
intPages = ActiveDocument.BuiltInDocumentProperties
(wdPropertyPages)
'Creates placeholder for White characters
Dim trayMarker As Integer
'Creates variable for the entire document
Dim myRange As Range
Documents("Document1").Activate
Set myRange = ThisDocument.Content
'Test Message
MsgBox "This document contains " & Documents.Count & "
pages."
'Sorting FOR Loop, finds each White character and prints
page accordingly'
For Sort = 1 To intPages
With myRange.Find
.Forward = True
.Font.Color = wdColorWhite
.Execute
If .Found = True Then
GoTo out
End If
End With
GoTo startover
'This is the part where it sends the Job to tray 1 or 2,
depending upon the FIND results
out:
MsgBox ("Found " & myRange)
If myRange = "1" Then
MsgBox ("Printing to Tray 1!")
Options.DefaultTrayID = wdPrinterUpperBin
ActiveDocument.PrintOut
Else
MsgBox ("Printing to Tray 2!")
Options.DefaultTrayID = wdPrinterLowerBin
ActiveDocument.PrintOut
End If
startover:
Next Sort
End Sub
Thanks.