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

Re: Access two printers at the same time by Word

Word
Fri Sep 19 09:03:59 CDT 2003

G'day tonytony1987@hotmail.com (Tony),

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


tonytony1987@hotmail.com (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 steve@wordheretic.com
Products http://www.geocities.com/word_heretic/products.html

Replies offlist may require payment.

Re: Access two printers at the same time by Lars-Eric

Lars-Eric
Fri Sep 19 18:58:46 CDT 2003

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

"Tony" <tonytony1987@hotmail.com> skrev i meddelandet
news:3015b48a.0309160242.77fd0342@posting.google.com...
> 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



Re: Access two printers at the same time by Lars-Eric

Lars-Eric
Fri Sep 19 19:03:25 CDT 2003

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


"Lars-Eric Gisslén" <lars.gisslen@_DelUnderscoreAndBetween_chello.se> skrev
i meddelandet news:NJMab.5184$P51.8273@amstwist00...
> 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
>
> "Tony" <tonytony1987@hotmail.com> skrev i meddelandet
> news:3015b48a.0309160242.77fd0342@posting.google.com...
> > 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
>
>



Re: Access two printers at the same time by tonytony1987

tonytony1987
Sun Sep 28 01:48:18 CDT 2003

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> wrote in message news:<8OMab.5185$P51.8093@amstwist00>...
> 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
>
>
> "Lars-Eric Gisslén" <lars.gisslen@_DelUnderscoreAndBetween_chello.se> skrev
> i meddelandet news:NJMab.5184$P51.8273@amstwist00...
> > 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
> >
> > "Tony" <tonytony1987@hotmail.com> skrev i meddelandet
> > news:3015b48a.0309160242.77fd0342@posting.google.com...
> > > 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
> >
> >

Re: Access two printers at the same time by Lars-Eric

Lars-Eric
Sun Sep 28 08:11:31 CDT 2003

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" <tonytony1987@hotmail.com> skrev i meddelandet
news:3015b48a.0309272248.2088b438@posting.google.com...
> 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>
wrote in message news:<8OMab.5185$P51.8093@amstwist00>...
> > 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
> >
> >
> > "Lars-Eric Gisslén" <lars.gisslen@_DelUnderscoreAndBetween_chello.se>
skrev
> > i meddelandet news:NJMab.5184$P51.8273@amstwist00...
> > > 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
> > >
> > > "Tony" <tonytony1987@hotmail.com> skrev i meddelandet
> > > news:3015b48a.0309160242.77fd0342@posting.google.com...
> > > > 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
> > >
> > >