Access two printers at the same time

T

Tony

Hello

I would like to print to two printers from the one word document.

The first will be the main document that will be a mailout which will
print on
a laser printer, the second part will be an address label printed on a
dedicated label printer (continuous roll).
This can be done by changing default printers each time I print either
the letter or the address label, however is it possible to perform the
task with one action if there are bulk letters to be printed?

My understanding is that an elaborate macro would be required to
achieve this, as I have not come to grips with macro writing i am
seeking some guidance.

regards

Tony
 
W

Word Heretic

G'day (e-mail address removed) (Tony),

I can offer you some commercial assitance of required, else try
scanning google, www.mvps.org/word links etc


(e-mail address removed) (Tony) was spinning this yarn:
Hello

I would like to print to two printers from the one word document.

The first will be the main document that will be a mailout which will
print on
a laser printer, the second part will be an address label printed on a
dedicated label printer (continuous roll).
This can be done by changing default printers each time I print either
the letter or the address label, however is it possible to perform the
task with one action if there are bulk letters to be printed?

My understanding is that an elaborate macro would be required to
achieve this, as I have not come to grips with macro writing i am
seeking some guidance.

regards

Tony

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
Email (e-mail address removed)
Products http://www.geocities.com/word_heretic/products.html

Replies offlist may require payment.
 
L

Lars-Eric Gisslén

Tony,

This is not a solution but a suggestion. Let the user choose to which
printer each printing should go to from a dialog. Create two listboxes in
the dialog, one for the documents and on for the labels, and populate them
with the printer names. Store the printer names the user selected in the
registry and use them as default later on. Don't forget to give the user the
option to change it later.

In your code you can have the following logic:
*Get the printer names from the registry (se Get/SaveSetting functions)
*Save the 'ActivePrinter'
*Set the ActivePrinter for the document
*Print the document
*Set the AtivePrinter for the labels
*Print the labels
*Restore the ActivePrinter setting

To get the names of the printers you can use the following code:
'-----------------------------
Private Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" _
(ByVal pTraget As String, ByVal pSource As Long) As Long
Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" _
(ByVal pString As Long) As Long
Private Declare Function EnumPrinters Lib "winspool.drv" _
Alias "EnumPrintersA" (ByVal nFlags As Long, _
ByVal pName As String, ByVal nLevel As Long, _
pPrinterEnum As Long, ByVal nBufLen As Long, _
pNeeded As Long, pPrtReturned As Long) As Long
Const PRINTER_ENUM_LOCAL = &H2
Const PRINTER_ENUM_NETWORK = &H40
Option Explicit
'-----------------------------
Function GetPrinters() As Collection
Dim aLngBuff() As Long
Dim nBytes As Long
Dim nNeeded As Long
Dim nNumPrinters As Long
Dim i As Long
Dim sPrtName As String
Dim nRetval As Long
Dim nElement As Long
Dim cRetVal As Collection

' Initialize variables
Set cRetVal = New Collection
Set GetPrinters = cRetVal
nBytes = 0
ReDim aLngBuff(0) As Long

' Get the required buffer size
nRetval = EnumPrinters(PRINTER_ENUM_LOCAL, "", _
1, aLngBuff(0), nBytes, nNeeded, nNumPrinters)

If nRetval = 0 Or nNeeded = 0 Then
' An error occured during the call
' or no printers found
Exit Function
End If

nBytes = nNeeded
' Resize the Long Array buffer
ReDim aLngBuff(Int(nBytes / 4) + 1) As Long

' Get the printers
nRetval = EnumPrinters(PRINTER_ENUM_LOCAL, "", _
1, aLngBuff(0), nBytes, nNeeded, nNumPrinters)

If nRetval = 0 Then
' An error occured during the call
Exit Function
End If

For i = 0 To nNumPrinters - 1
nElement = 4 * i + 2 ' Calculate the array element
' Get the size of the string and size the variable
sPrtName = Space(lstrlen(aLngBuff(nElement)))
' Copy the string from the API call to our variable
nRetval = lstrcpy(sPrtName, aLngBuff(nElement))
' Add the string to the collection
cRetVal.Add sPrtName
Next

End Function

'-----------------------------

Regards,
Lars-Eric
 
L

Lars-Eric Gisslén

Sorry, a typo. A Copy/Paste problem :)

This If statement: (first one)

If nRetval = 0 Or nNeeded = 0 Then
' An error occured during the call
' or no printers found
Exit Function
End If

should be


If nNeeded = 0 Then
' An error occured during the call
' or no printers found
Exit Function
End If
 
T

Tony

Hello Lars-Eric Gisslen

Thank for the suggestion, I will give this a try.
If the user can accept this method it will be great.

regards

Tony
 
L

Lars-Eric Gisslén

Tony,

Keep in mind that the code I provided is a stripped down version of what we
actually use, the code I provided only list local printers. The real code
also checks for network printers (a little bit more complicated) but as my
employer owns the code I can't share it here. If you would need to get
network printers also, I can provide you with the steps you need to take to
get them.

Regards,
Lars-Eric

Tony said:
Hello Lars-Eric Gisslen

Thank for the suggestion, I will give this a try.
If the user can accept this method it will be great.

regards

Tony

"Lars-Eric Gisslén" <lars.gisslen@_DelUnderscoreAndBetween_chello.se>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top