B
BruceM
I have code in a Startup template that prints a selected section of a
document on a color printer. I use bookmarks to define the beginning and
end of the section to be printed. Code loops through all available
printers, and selects one with "Color Laser" in the printer name. If there
is no such printer, the default printer is used. If no printers are
installed, an error message is produced.
I developed the code on a computer with Office 2003. It has been working on
Office 2003 and Office 2000 machines until recently, when it stopped working
on an Office 2000 machine. There are only a handful of Office 2000
machines, and I have not been able to locate another one to test whether the
problem lies in the version of Office or it is something else, but in any
case it is a problem I need to solve.
Here is the part of the code where the problem occurs:
If IsBounded(varPrinters) Then ' IsBounded is in mdlPrintSelection
For i = LBound(varPrinters) To UBound(varPrinters)
If InStr(varPrinters(i), "Color Laser") Then
ActivePrinter = varPrinters(i) ' TROUBLE LINE
GoTo PrintDoc
End If
Next i
Else
MsgBox "No printers found"
Exit Sub
End If
IsBounded is a small function that tests whether varPrinters is an array.
varPrinters is an array created by another function that lists all available
printers. That function is ListPrinters from the mvps web site:
http://word.mvps.org/FAQs/MacrosVBA/AvailablePrinters.htm
All works as intended until the line I marked as TROUBLE LINE, when Word
freezes on the Office 2000 computer. This started very recently. It had
been working, then suddenly it did not.
I set watches on ActivePrinter and varPrinters(i). At the marked line of
code, this is ActivePrinter:
Dell Color Laser 5110cn PCL6 on NE08
This is varPrinters(i):
Dell Color Laser 5110cn PCL6
It is the same on the computers where it works and the one where it doesn't.
BTW, use of GoTo is something I rarely do. There is more code between Next
1 and Else that allows the user to print to the default printer if no color
laser printer is available, but it is not relevant to the problem at hand.
GoTo ended up being the best way I could find to skip that extra code if a
color laser printer is in fact available.
document on a color printer. I use bookmarks to define the beginning and
end of the section to be printed. Code loops through all available
printers, and selects one with "Color Laser" in the printer name. If there
is no such printer, the default printer is used. If no printers are
installed, an error message is produced.
I developed the code on a computer with Office 2003. It has been working on
Office 2003 and Office 2000 machines until recently, when it stopped working
on an Office 2000 machine. There are only a handful of Office 2000
machines, and I have not been able to locate another one to test whether the
problem lies in the version of Office or it is something else, but in any
case it is a problem I need to solve.
Here is the part of the code where the problem occurs:
If IsBounded(varPrinters) Then ' IsBounded is in mdlPrintSelection
For i = LBound(varPrinters) To UBound(varPrinters)
If InStr(varPrinters(i), "Color Laser") Then
ActivePrinter = varPrinters(i) ' TROUBLE LINE
GoTo PrintDoc
End If
Next i
Else
MsgBox "No printers found"
Exit Sub
End If
IsBounded is a small function that tests whether varPrinters is an array.
varPrinters is an array created by another function that lists all available
printers. That function is ListPrinters from the mvps web site:
http://word.mvps.org/FAQs/MacrosVBA/AvailablePrinters.htm
All works as intended until the line I marked as TROUBLE LINE, when Word
freezes on the Office 2000 computer. This started very recently. It had
been working, then suddenly it did not.
I set watches on ActivePrinter and varPrinters(i). At the marked line of
code, this is ActivePrinter:
Dell Color Laser 5110cn PCL6 on NE08
This is varPrinters(i):
Dell Color Laser 5110cn PCL6
It is the same on the computers where it works and the one where it doesn't.
BTW, use of GoTo is something I rarely do. There is more code between Next
1 and Else that allows the user to print to the default printer if no color
laser printer is available, but it is not relevant to the problem at hand.
GoTo ended up being the best way I could find to skip that extra code if a
color laser printer is in fact available.