Macro -duplex printing

I  am trying to write a macro in a template (.dot) file to be used on around 
2000 documents based on it. The macro has code to print duplex. The code is 
give below. I get error 'Unable to set shared printer settings' while trying 
to assign printersettings. Isnt it the same like changing the Duplex setting 
in the print->printing preferances? 
Please advice.


Option Explicit

   Public Type PRINTER_DEFAULTS

       pDatatype As Long
       pDevmode As Long
       DesiredAccess As Long
   End Type

   Public Type PRINTER_INFO_2
       pServerName As Long
       pPrinterName As Long
       pShareName As Long
       pPortName As Long
       pDriverName As Long
       pComment As Long
       pLocation As Long
       pDevmode As Long       ' Pointer to DEVMODE
       pSepFile As Long
       pPrintProcessor As Long
       pDatatype As Long
       pParameters As Long
       pSecurityDescriptor As Long  ' Pointer to SECURITY_DESCRIPTOR
       Attributes As Long


       Priority As Long
       DefaultPriority As Long
       StartTime As Long
       UntilTime As Long
       Status As Long
       cJobs As Long
       AveragePPM As Long
   End Type

   Public Type DEVMODE
       dmDeviceName As String * 32

       dmSpecVersion As Integer
       dmDriverVersion As Integer
       dmSize As Integer
       dmDriverExtra As Integer
       dmFields As Long
       dmOrientation As Integer
       dmPaperSize As Integer
       dmPaperLength As Integer
       dmPaperWidth As Integer
       dmScale As Integer
       dmCopies As Integer
       dmDefaultSource As Integer
       dmPrintQuality As Integer
       dmColor As Integer
       dmDuplex As Integer
       dmYResolution As Integer
       dmTTOption As Integer
       dmCollate As Integer
       dmFormName As String * 32
       dmUnusedPadding As Integer
       dmBitsPerPel As Integer
       dmPelsWidth As Long
       dmPelsHeight As Long
       dmDisplayFlags As Long
       dmDisplayFrequency As Long
       dmICMMethod As Long
       dmICMIntent As Long
       dmMediaType As Long
       dmDitherType As Long
       dmReserved1 As Long
       dmReserved2 As Long
   End Type

   Public Const DM_DUPLEX = &H1000&
   Public Const DM_IN_BUFFER = 8

   Public Const DM_OUT_BUFFER = 2
   Public Const PRINTER_ACCESS_ADMINISTER = &H4
   Public Const PRINTER_ACCESS_USE = &H8
   Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
   'Public Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or 
PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)

   Public Declare Function ClosePrinter Lib "winspool.drv" _
    (ByVal hPrinter As Long) As Long
   Public Declare Function DocumentProperties Lib "winspool.drv" _
     Alias "DocumentPropertiesA" (ByVal hwnd As Long, _
     ByVal hPrinter As Long, ByVal pDeviceName As String, _
     ByVal pDevModeOutput As Long, ByVal pDevModeInput As Long, _
     ByVal fMode As Long) As Long
   Public Declare Function GetPrinter Lib "winspool.drv" Alias _
     "GetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
     pPrinter As Byte, ByVal cbBuf As Long, pcbNeeded As Long) As Long
   Public Declare Function OpenPrinter Lib "winspool.drv" Alias _
     "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
     pDefault As PRINTER_DEFAULTS) As Long
   Public Declare Function SetPrinter Lib "winspool.drv" Alias _
     "SetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
     pPrinter As Byte, ByVal Command As Long) As Long

   Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (pDest As Any, pSource As Any, ByVal cbLength As Long)


   ' ==================================================================
   ' SetPrinterDuplex
   '
   '  Programmatically set the Duplex flag for the specified printer
   '  driver's default properties.
   '
   '  Returns: True on success, False on error. (An error will also

   '  display a message box. This is done for informational value
   '  only. You should modify the code to support better error
   '  handling in your production application.)
   '
   '  Parameters:
   '    sPrinterName - The name of the printer to be used.
   '
   '    nDuplexSetting - One of the following standard settings:
   '       1 = None
   '       2 = Duplex on long edge (book)
   '       3 = Duplex on short edge (legal)
   '
   ' ==================================================================
Public Function SetPrinterDuplex(ByVal s2ndFloorBinder As String, ByVal 
nDuplexSetting As Long) As Boolean

      Dim hPrinter As Long
      Dim pd As PRINTER_DEFAULTS
      Dim pinfo As PRINTER_INFO_2
      Dim dm As DEVMODE
   
      Dim yDevModeData() As Byte
      Dim yPInfoMemory() As Byte
      Dim nBytesNeeded As Long
      Dim nRet As Long, nJunk As Long
   
      On Error GoTo cleanup
   
      If (nDuplexSetting < 1) Or (nDuplexSetting > 3) Then
         MsgBox "Error: dwDuplexSetting is incorrect."
         Exit Function
      End If
      
      pd.DesiredAccess = PRINTER_ACCESS_USE
      nRet = OpenPrinter(s2ndFloorBinder, hPrinter, pd)
      If (nRet = 0) Or (hPrinter = 0) Then
         If Err.LastDllError = 5 Then
            MsgBox "Access denied -- See the article for more info."
         Else
            MsgBox "Cannot open the printer specified " & _
              "(make sure the printer name is correct)."
         End If
         Exit Function
      End If
   
      nRet = DocumentProperties(0, hPrinter, s2ndFloorBinder, 0, 0, 0)
      If (nRet < 0) Then
         MsgBox "Cannot get the size of the DEVMODE structure."
         GoTo cleanup
      End If
   
      ReDim yDevModeData(nRet + 100) As Byte
      nRet = DocumentProperties(0, hPrinter, s2ndFloorBinder, _
                  VarPtr(yDevModeData(0)), 0, DM_OUT_BUFFER)
      If (nRet < 0) Then
         MsgBox "Cannot get the DEVMODE structure."
         GoTo cleanup
      End If
   
      Call CopyMemory(dm, yDevModeData(0), Len(dm))
   
      If Not CBool(dm.dmFields And DM_DUPLEX) Then
        MsgBox "You cannot modify the duplex flag for this printer " & _
               "because it does not support duplex or the driver " & _
               "does not support setting it from the Windows API."
         GoTo cleanup
      End If
   
      dm.dmDuplex = nDuplexSetting
      Call CopyMemory(yDevModeData(0), dm, Len(dm))
   
      nRet = DocumentProperties(0, hPrinter, s2ndFloorBinder, _
        VarPtr(yDevModeData(0)), VarPtr(yDevModeData(0)), _
        DM_IN_BUFFER Or DM_OUT_BUFFER)

      If (nRet < 0) Then
        MsgBox "Unable to set duplex setting to this printer."
        GoTo cleanup
      End If
   
      Call GetPrinter(hPrinter, 2, 0, 0, nBytesNeeded)
      If (nBytesNeeded = 0) Then GoTo cleanup
   
      ReDim yPInfoMemory(nBytesNeeded + 100) As Byte

      nRet = GetPrinter(hPrinter, 2, yPInfoMemory(0), nBytesNeeded, nJunk)
      If (nRet = 0) Then
         MsgBox "Unable to get shared printer settings."
         GoTo cleanup
      End If
   
      Call CopyMemory(pinfo, yPInfoMemory(0), Len(pinfo))
      pinfo.pDevmode = VarPtr(yDevModeData(0))
      pinfo.pSecurityDescriptor = 0
      Call CopyMemory(yPInfoMemory(0), pinfo, Len(pinfo))
   
      nRet = SetPrinter(hPrinter, 2, yPInfoMemory(0), 0)
      If (nRet = 0) Then
         MsgBox "Unable to set shared printer settings."
      End If
   
      SetPrinterDuplex = CBool(nRet)

cleanup:
      If (hPrinter <> 0) Then Call ClosePrinter(hPrinter)

   End Function

Sub Duplexprinting()

   
    Dim sPrinterName  As String
    sPrinterName = Trim$(Left$(ActivePrinter, InStr(ActivePrinter, " on ")))
        
    If SetPrinterDuplex(sPrinterName, 2) Then
        If MsgBox("Shall I Print?", vbYesNo) = vbYes Then
        Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
            wdPrintDocumentContent, Copies:=1, Pages:="", 
PageType:=wdPrintAllPages, _
            Collate:=True, Background:=True, PrintToFile:=False, 
PrintZoomColumn:=0, _
            PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
        End If
        SetPrinterDuplex sPrinterName, 1
    End If
End Sub

0
Utf
1/21/2010 8:40:02 AM
mac.office.word 1676 articles. 1 followers. Follow

2 Replies
1426 Views

Similar Articles

[PageSpeed] 58

You're asking in the wrong place: this is the Macintosh Word group here: we
could probably tell you how to do this in Objective C on an OS X Server, but
we're a bit lost in Windows.

And I am not sure why you are even bothering: wouldn't it be so much simpler
to create a PPD (a "Printer") with its default set to "Duplex" and call it?

Cheers

On 21/01/10 7:40 PM, in article
531E7603-3B27-4BAA-B67E-FE1F1630F9D4@microsoft.com, "Vidhya"
<Vidhya@discussions.microsoft.com> wrote:

> I  am trying to write a macro in a template (.dot) file to be used on around
> 2000 documents based on it. The macro has code to print duplex. The code is
> give below. I get error 'Unable to set shared printer settings' while trying
> to assign printersettings. Isnt it the same like changing the Duplex setting
> in the print->printing preferances?
> Please advice.
> 
> 
> Option Explicit
> 
>    Public Type PRINTER_DEFAULTS
> 
>        pDatatype As Long
>        pDevmode As Long
>        DesiredAccess As Long
>    End Type
> 
>    Public Type PRINTER_INFO_2
>        pServerName As Long
>        pPrinterName As Long
>        pShareName As Long
>        pPortName As Long
>        pDriverName As Long
>        pComment As Long
>        pLocation As Long
>        pDevmode As Long       ' Pointer to DEVMODE
>        pSepFile As Long
>        pPrintProcessor As Long
>        pDatatype As Long
>        pParameters As Long
>        pSecurityDescriptor As Long  ' Pointer to SECURITY_DESCRIPTOR
>        Attributes As Long
> 
> 
>        Priority As Long
>        DefaultPriority As Long
>        StartTime As Long
>        UntilTime As Long
>        Status As Long
>        cJobs As Long
>        AveragePPM As Long
>    End Type
> 
>    Public Type DEVMODE
>        dmDeviceName As String * 32
> 
>        dmSpecVersion As Integer
>        dmDriverVersion As Integer
>        dmSize As Integer
>        dmDriverExtra As Integer
>        dmFields As Long
>        dmOrientation As Integer
>        dmPaperSize As Integer
>        dmPaperLength As Integer
>        dmPaperWidth As Integer
>        dmScale As Integer
>        dmCopies As Integer
>        dmDefaultSource As Integer
>        dmPrintQuality As Integer
>        dmColor As Integer
>        dmDuplex As Integer
>        dmYResolution As Integer
>        dmTTOption As Integer
>        dmCollate As Integer
>        dmFormName As String * 32
>        dmUnusedPadding As Integer
>        dmBitsPerPel As Integer
>        dmPelsWidth As Long
>        dmPelsHeight As Long
>        dmDisplayFlags As Long
>        dmDisplayFrequency As Long
>        dmICMMethod As Long
>        dmICMIntent As Long
>        dmMediaType As Long
>        dmDitherType As Long
>        dmReserved1 As Long
>        dmReserved2 As Long
>    End Type
> 
>    Public Const DM_DUPLEX = &H1000&
>    Public Const DM_IN_BUFFER = 8
> 
>    Public Const DM_OUT_BUFFER = 2
>    Public Const PRINTER_ACCESS_ADMINISTER = &H4
>    Public Const PRINTER_ACCESS_USE = &H8
>    Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
>    'Public Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or
> PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)
> 
>    Public Declare Function ClosePrinter Lib "winspool.drv" _
>     (ByVal hPrinter As Long) As Long
>    Public Declare Function DocumentProperties Lib "winspool.drv" _
>      Alias "DocumentPropertiesA" (ByVal hwnd As Long, _
>      ByVal hPrinter As Long, ByVal pDeviceName As String, _
>      ByVal pDevModeOutput As Long, ByVal pDevModeInput As Long, _
>      ByVal fMode As Long) As Long
>    Public Declare Function GetPrinter Lib "winspool.drv" Alias _
>      "GetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
>      pPrinter As Byte, ByVal cbBuf As Long, pcbNeeded As Long) As Long
>    Public Declare Function OpenPrinter Lib "winspool.drv" Alias _
>      "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
>      pDefault As PRINTER_DEFAULTS) As Long
>    Public Declare Function SetPrinter Lib "winspool.drv" Alias _
>      "SetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
>      pPrinter As Byte, ByVal Command As Long) As Long
> 
>    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
>     (pDest As Any, pSource As Any, ByVal cbLength As Long)
> 
> 
>    ' ==================================================================
>    ' SetPrinterDuplex
>    '
>    '  Programmatically set the Duplex flag for the specified printer
>    '  driver's default properties.
>    '
>    '  Returns: True on success, False on error. (An error will also
> 
>    '  display a message box. This is done for informational value
>    '  only. You should modify the code to support better error
>    '  handling in your production application.)
>    '
>    '  Parameters:
>    '    sPrinterName - The name of the printer to be used.
>    '
>    '    nDuplexSetting - One of the following standard settings:
>    '       1 = None
>    '       2 = Duplex on long edge (book)
>    '       3 = Duplex on short edge (legal)
>    '
>    ' ==================================================================
> Public Function SetPrinterDuplex(ByVal s2ndFloorBinder As String, ByVal
> nDuplexSetting As Long) As Boolean
> 
>       Dim hPrinter As Long
>       Dim pd As PRINTER_DEFAULTS
>       Dim pinfo As PRINTER_INFO_2
>       Dim dm As DEVMODE
>    
>       Dim yDevModeData() As Byte
>       Dim yPInfoMemory() As Byte
>       Dim nBytesNeeded As Long
>       Dim nRet As Long, nJunk As Long
>    
>       On Error GoTo cleanup
>    
>       If (nDuplexSetting < 1) Or (nDuplexSetting > 3) Then
>          MsgBox "Error: dwDuplexSetting is incorrect."
>          Exit Function
>       End If
>       
>       pd.DesiredAccess = PRINTER_ACCESS_USE
>       nRet = OpenPrinter(s2ndFloorBinder, hPrinter, pd)
>       If (nRet = 0) Or (hPrinter = 0) Then
>          If Err.LastDllError = 5 Then
>             MsgBox "Access denied -- See the article for more info."
>          Else
>             MsgBox "Cannot open the printer specified " & _
>               "(make sure the printer name is correct)."
>          End If
>          Exit Function
>       End If
>    
>       nRet = DocumentProperties(0, hPrinter, s2ndFloorBinder, 0, 0, 0)
>       If (nRet < 0) Then
>          MsgBox "Cannot get the size of the DEVMODE structure."
>          GoTo cleanup
>       End If
>    
>       ReDim yDevModeData(nRet + 100) As Byte
>       nRet = DocumentProperties(0, hPrinter, s2ndFloorBinder, _
>                   VarPtr(yDevModeData(0)), 0, DM_OUT_BUFFER)
>       If (nRet < 0) Then
>          MsgBox "Cannot get the DEVMODE structure."
>          GoTo cleanup
>       End If
>    
>       Call CopyMemory(dm, yDevModeData(0), Len(dm))
>    
>       If Not CBool(dm.dmFields And DM_DUPLEX) Then
>         MsgBox "You cannot modify the duplex flag for this printer " & _
>                "because it does not support duplex or the driver " & _
>                "does not support setting it from the Windows API."
>          GoTo cleanup
>       End If
>    
>       dm.dmDuplex = nDuplexSetting
>       Call CopyMemory(yDevModeData(0), dm, Len(dm))
>    
>       nRet = DocumentProperties(0, hPrinter, s2ndFloorBinder, _
>         VarPtr(yDevModeData(0)), VarPtr(yDevModeData(0)), _
>         DM_IN_BUFFER Or DM_OUT_BUFFER)
> 
>       If (nRet < 0) Then
>         MsgBox "Unable to set duplex setting to this printer."
>         GoTo cleanup
>       End If
>    
>       Call GetPrinter(hPrinter, 2, 0, 0, nBytesNeeded)
>       If (nBytesNeeded = 0) Then GoTo cleanup
>    
>       ReDim yPInfoMemory(nBytesNeeded + 100) As Byte
> 
>       nRet = GetPrinter(hPrinter, 2, yPInfoMemory(0), nBytesNeeded, nJunk)
>       If (nRet = 0) Then
>          MsgBox "Unable to get shared printer settings."
>          GoTo cleanup
>       End If
>    
>       Call CopyMemory(pinfo, yPInfoMemory(0), Len(pinfo))
>       pinfo.pDevmode = VarPtr(yDevModeData(0))
>       pinfo.pSecurityDescriptor = 0
>       Call CopyMemory(yPInfoMemory(0), pinfo, Len(pinfo))
>    
>       nRet = SetPrinter(hPrinter, 2, yPInfoMemory(0), 0)
>       If (nRet = 0) Then
>          MsgBox "Unable to set shared printer settings."
>       End If
>    
>       SetPrinterDuplex = CBool(nRet)
> 
> cleanup:
>       If (hPrinter <> 0) Then Call ClosePrinter(hPrinter)
> 
>    End Function
> 
> Sub Duplexprinting()
> 
>    
>     Dim sPrinterName  As String
>     sPrinterName = Trim$(Left$(ActivePrinter, InStr(ActivePrinter, " on ")))
>         
>     If SetPrinterDuplex(sPrinterName, 2) Then
>         If MsgBox("Shall I Print?", vbYesNo) = vbYes Then
>         Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
>             wdPrintDocumentContent, Copies:=1, Pages:="",
> PageType:=wdPrintAllPages, _
>             Collate:=True, Background:=True, PrintToFile:=False,
> PrintZoomColumn:=0, _
>             PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
>         End If
>         SetPrinterDuplex sPrinterName, 1
>     End If
> End Sub
> 

This email is my business email -- Please do not email me about forum
matters unless you intend to pay!

 -- 

John McGhie, Microsoft MVP (Word, Mac Word), Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. | Ph: +61 (0)4 1209 1410
+61 4 1209 1410, mailto:john@mcghie.name


0
John
1/21/2010 10:30:42 AM
sorry aboutt he wrong placement of the question. But as far to anwer to your 
reply, I would like to put the template file in the network allowing multiple 
users access the document. They might not want to have a dedicated printer 
with duplex setting. The template should allow the user to just click a menu 
button and print in duplex format using the default printer.

Thanks . Will pose this question at the relevant place. 


"John McGhie" wrote:

> You're asking in the wrong place: this is the Macintosh Word group here: we
> could probably tell you how to do this in Objective C on an OS X Server, but
> we're a bit lost in Windows.
> 
> And I am not sure why you are even bothering: wouldn't it be so much simpler
> to create a PPD (a "Printer") with its default set to "Duplex" and call it?
> 
> Cheers
> 
> On 21/01/10 7:40 PM, in article
> 531E7603-3B27-4BAA-B67E-FE1F1630F9D4@microsoft.com, "Vidhya"
> <Vidhya@discussions.microsoft.com> wrote:
> 
> > I  am trying to write a macro in a template (.dot) file to be used on around
> > 2000 documents based on it. The macro has code to print duplex. The code is
> > give below. I get error 'Unable to set shared printer settings' while trying
> > to assign printersettings. Isnt it the same like changing the Duplex setting
> > in the print->printing preferances?
> > Please advice.
> > 
> > 
> > Option Explicit
> > 
> >    Public Type PRINTER_DEFAULTS
> > 
> >        pDatatype As Long
> >        pDevmode As Long
> >        DesiredAccess As Long
> >    End Type
> > 
> >    Public Type PRINTER_INFO_2
> >        pServerName As Long
> >        pPrinterName As Long
> >        pShareName As Long
> >        pPortName As Long
> >        pDriverName As Long
> >        pComment As Long
> >        pLocation As Long
> >        pDevmode As Long       ' Pointer to DEVMODE
> >        pSepFile As Long
> >        pPrintProcessor As Long
> >        pDatatype As Long
> >        pParameters As Long
> >        pSecurityDescriptor As Long  ' Pointer to SECURITY_DESCRIPTOR
> >        Attributes As Long
> > 
> > 
> >        Priority As Long
> >        DefaultPriority As Long
> >        StartTime As Long
> >        UntilTime As Long
> >        Status As Long
> >        cJobs As Long
> >        AveragePPM As Long
> >    End Type
> > 
> >    Public Type DEVMODE
> >        dmDeviceName As String * 32
> > 
> >        dmSpecVersion As Integer
> >        dmDriverVersion As Integer
> >        dmSize As Integer
> >        dmDriverExtra As Integer
> >        dmFields As Long
> >        dmOrientation As Integer
> >        dmPaperSize As Integer
> >        dmPaperLength As Integer
> >        dmPaperWidth As Integer
> >        dmScale As Integer
> >        dmCopies As Integer
> >        dmDefaultSource As Integer
> >        dmPrintQuality As Integer
> >        dmColor As Integer
> >        dmDuplex As Integer
> >        dmYResolution As Integer
> >        dmTTOption As Integer
> >        dmCollate As Integer
> >        dmFormName As String * 32
> >        dmUnusedPadding As Integer
> >        dmBitsPerPel As Integer
> >        dmPelsWidth As Long
> >        dmPelsHeight As Long
> >        dmDisplayFlags As Long
> >        dmDisplayFrequency As Long
> >        dmICMMethod As Long
> >        dmICMIntent As Long
> >        dmMediaType As Long
> >        dmDitherType As Long
> >        dmReserved1 As Long
> >        dmReserved2 As Long
> >    End Type
> > 
> >    Public Const DM_DUPLEX = &H1000&
> >    Public Const DM_IN_BUFFER = 8
> > 
> >    Public Const DM_OUT_BUFFER = 2
> >    Public Const PRINTER_ACCESS_ADMINISTER = &H4
> >    Public Const PRINTER_ACCESS_USE = &H8
> >    Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
> >    'Public Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or
> > PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)
> > 
> >    Public Declare Function ClosePrinter Lib "winspool.drv" _
> >     (ByVal hPrinter As Long) As Long
> >    Public Declare Function DocumentProperties Lib "winspool.drv" _
> >      Alias "DocumentPropertiesA" (ByVal hwnd As Long, _
> >      ByVal hPrinter As Long, ByVal pDeviceName As String, _
> >      ByVal pDevModeOutput As Long, ByVal pDevModeInput As Long, _
> >      ByVal fMode As Long) As Long
> >    Public Declare Function GetPrinter Lib "winspool.drv" Alias _
> >      "GetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
> >      pPrinter As Byte, ByVal cbBuf As Long, pcbNeeded As Long) As Long
> >    Public Declare Function OpenPrinter Lib "winspool.drv" Alias _
> >      "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
> >      pDefault As PRINTER_DEFAULTS) As Long
> >    Public Declare Function SetPrinter Lib "winspool.drv" Alias _
> >      "SetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
> >      pPrinter As Byte, ByVal Command As Long) As Long
> > 
> >    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
> >     (pDest As Any, pSource As Any, ByVal cbLength As Long)
> > 
> > 
> >    ' ==================================================================
> >    ' SetPrinterDuplex
> >    '
> >    '  Programmatically set the Duplex flag for the specified printer
> >    '  driver's default properties.
> >    '
> >    '  Returns: True on success, False on error. (An error will also
> > 
> >    '  display a message box. This is done for informational value
> >    '  only. You should modify the code to support better error
> >    '  handling in your production application.)
> >    '
> >    '  Parameters:
> >    '    sPrinterName - The name of the printer to be used.
> >    '
> >    '    nDuplexSetting - One of the following standard settings:
> >    '       1 = None
> >    '       2 = Duplex on long edge (book)
> >    '       3 = Duplex on short edge (legal)
> >    '
> >    ' ==================================================================
> > Public Function SetPrinterDuplex(ByVal s2ndFloorBinder As String, ByVal
> > nDuplexSetting As Long) As Boolean
> > 
> >       Dim hPrinter As Long
> >       Dim pd As PRINTER_DEFAULTS
> >       Dim pinfo As PRINTER_INFO_2
> >       Dim dm As DEVMODE
> >    
> >       Dim yDevModeData() As Byte
> >       Dim yPInfoMemory() As Byte
> >       Dim nBytesNeeded As Long
> >       Dim nRet As Long, nJunk As Long
> >    
> >       On Error GoTo cleanup
> >    
> >       If (nDuplexSetting < 1) Or (nDuplexSetting > 3) Then
> >          MsgBox "Error: dwDuplexSetting is incorrect."
> >          Exit Function
> >       End If
> >       
> >       pd.DesiredAccess = PRINTER_ACCESS_USE
> >       nRet = OpenPrinter(s2ndFloorBinder, hPrinter, pd)
> >       If (nRet = 0) Or (hPrinter = 0) Then
> >          If Err.LastDllError = 5 Then
> >             MsgBox "Access denied -- See the article for more info."
> >          Else
> >             MsgBox "Cannot open the printer specified " & _
> >               "(make sure the printer name is correct)."
> >          End If
> >          Exit Function
> >       End If
> >    
> >       nRet = DocumentProperties(0, hPrinter, s2ndFloorBinder, 0, 0, 0)
> >       If (nRet < 0) Then
> >          MsgBox "Cannot get the size of the DEVMODE structure."
> >          GoTo cleanup
> >       End If
> >    
> >       ReDim yDevModeData(nRet + 100) As Byte
> >       nRet = DocumentProperties(0, hPrinter, s2ndFloorBinder, _
> >                   VarPtr(yDevModeData(0)), 0, DM_OUT_BUFFER)
> >       If (nRet < 0) Then
> >          MsgBox "Cannot get the DEVMODE structure."
> >          GoTo cleanup
> >       End If
> >    
> >       Call CopyMemory(dm, yDevModeData(0), Len(dm))
> >    
> >       If Not CBool(dm.dmFields And DM_DUPLEX) Then
> >         MsgBox "You cannot modify the duplex flag for this printer " & _
> >                "because it does not support duplex or the driver " & _
> >                "does not support setting it from the Windows API."
> >          GoTo cleanup
> >       End If
> >    
> >       dm.dmDuplex = nDuplexSetting
> >       Call CopyMemory(yDevModeData(0), dm, Len(dm))
> >    
> >       nRet = DocumentProperties(0, hPrinter, s2ndFloorBinder, _
> >         VarPtr(yDevModeData(0)), VarPtr(yDevModeData(0)), _
> >         DM_IN_BUFFER Or DM_OUT_BUFFER)
> > 
> >       If (nRet < 0) Then
> >         MsgBox "Unable to set duplex setting to this printer."
> >         GoTo cleanup
> >       End If
> >    
> >       Call GetPrinter(hPrinter, 2, 0, 0, nBytesNeeded)
> >       If (nBytesNeeded = 0) Then GoTo cleanup
> >    
> >       ReDim yPInfoMemory(nBytesNeeded + 100) As Byte
> > 
> >       nRet = GetPrinter(hPrinter, 2, yPInfoMemory(0), nBytesNeeded, nJunk)
> >       If (nRet = 0) Then
> >          MsgBox "Unable to get shared printer settings."
> >          GoTo cleanup
> >       End If
> >    
> >       Call CopyMemory(pinfo, yPInfoMemory(0), Len(pinfo))
> >       pinfo.pDevmode = VarPtr(yDevModeData(0))
> >       pinfo.pSecurityDescriptor = 0
> >       Call CopyMemory(yPInfoMemory(0), pinfo, Len(pinfo))
> >    
> >       nRet = SetPrinter(hPrinter, 2, yPInfoMemory(0), 0)
> >       If (nRet = 0) Then
> >          MsgBox "Unable to set shared printer settings."
> >       End If
> >    
> >       SetPrinterDuplex = CBool(nRet)
> > 
> > cleanup:
> >       If (hPrinter <> 0) Then Call ClosePrinter(hPrinter)
> > 
> >    End Function
> > 
> > Sub Duplexprinting()
> > 
> >    
> >     Dim sPrinterName  As String
> >     sPrinterName = Trim$(Left$(ActivePrinter, InStr(ActivePrinter, " on ")))
> >         
> >     If SetPrinterDuplex(sPrinterName, 2) Then
> >         If MsgBox("Shall I Print?", vbYesNo) = vbYes Then
> >         Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
> >             wdPrintDocumentContent, Copies:=1, Pages:="",
> > PageType:=wdPrintAllPages, _
> >             Collate:=True, Background:=True, PrintToFile:=False,
> > PrintZoomColumn:=0, _
> >             PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
> >         End If
> >         SetPrinterDuplex sPrinterName, 1
> >     End If
> > End Sub
> > 
> 
> This email is my business email -- Please do not email me about forum
> matters unless you intend to pay!
> 
>  -- 
> 
> John McGhie, Microsoft MVP (Word, Mac Word), Consultant Technical Writer,
> McGhie Information Engineering Pty Ltd
> Sydney, Australia. | Ph: +61 (0)4 1209 1410
> +61 4 1209 1410, mailto:john@mcghie.name
> 
> 
> .
> 
0
Utf
1/22/2010 1:31:01 AM
Reply:

Similar Artilces:

2-Sided Printing: HP Photosmart D7300 Series. Right edge of image clipped off, won't allow manual feed #2
We are wasting tons of paper trying to print a "booklet" 2 sided. Printer: HP Photosmart D7300 Paper 8.5x11 Booklet 5.5 x 8.5 Printer set at landscape Ran 2-side configuration wizard. Did all paper feeds (numbers and circles) When attempting to print, right side is clipped off No prompts appear to turn paper over. When printer is set to BORDERLESS, the full right side of image appears, but left side of page is trimmed off. "fit image to paper" option vanishes. Is there a way to do this? Thank you. How many pages? Is the print preview correct? I only know how I...

Crazy printing ...
I'm using XP (SP2) and XP Office. This includes Publisher 2003. I'm using a Canon S200 printer. This was previously attached to another computer running Win98SE. There were no printing problems. I installed it to the XP system using the Canon CD. Now however it goes crazy when I use Publisher. I'm trying to print a booklet, two A5 pages on a single A4 sheet. Everything pans out in Print Preview. When I print however, all sorts of crazy things happen. It shrinks the text to nothing. It prints portrait instead of landscape. And more. Whatever I tell it to do, it ignores. As far a...

Clip Art won't print #2
My operating system is Windows Vista, I have an HP Photosmart 8450 printer and when using Publisher 2007, none of the clip art will print. Actually, no clip art will print in any of the Office 2007 programs, but Publisher is the one that I was using when I discovered this. Has anyone else had this problem? Any suggestions on how to fix it? Thanks. Are you using updated drivers? -- JoAnn Paules Microsoft MVP - Publisher How to ask a question http://support.microsoft.com/kb/555375 "Ms. CCC-SLP" <Ms. CCC-SLP@discussions.microsoft.com> wrote in message news:577191CD...

excel macro on startup from DOS
After I start excel from a DOS .BAT script I want a macro to then be automatically executed. (To do this with MS Word you just put /Mmacroname after the path name of the executable, but this does not seem to work) Excel doesn't support macro execution from the command line. As an alternative, you can name the macro Auto_Open and this will execute when the workbook is opened. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "roblit" <anonymous@discussions.microsoft.com> wrote in message news:02AFEE4E-6686-4434-A41D-1...

Visual Basic Macros, relative position
Dear Experts, I am making a report, and I have a set of data, in a very looong row: MKT_VAL NET_ASSETS TOT_ASSETS 46 51 51 6233 6228 6228 Over 100 fields. I need this data to be changed to run down a column. MKT_VAL 46 6233 NET_ASSETS 51 6228 TOT_ASSETS 51 6228 I tried to make a macro to do this. It would be run after I copied and pasted the three column cells into another area. Sub ShiftNullData() ' ' ShiftNullData Macro ' Macro recorded 11/14/2006 by Rodger Lepinsky ' ' Keyboard Shortcut: Ctrl+q ' Range("A18").S...

printing #2
i am trying to print a flyer that has a picture i created myself. what i did was make a square, put 4 separate lines on top of it, then put the same square (except made it somewhat transparent by way of the fill options) and put it on top of it to so it would be transparent enough to be able to see a hint of the lines underneath...however, when I print it, it does not print what i see...it prints a the full solid background as if it were not transparent. how can i print it with the transparent effect i want? >-----Original Message----- >Stephanie what version of Publisher are y...

Unable to Print Timesheets in BP
We recently installed BP, PDK and Great Plains. We are experiencing significant difficulty in printing the beautiful looking timesheet that displays when hitting the "Print" button in Business Portal. The timesheet data basically bleeds off of the right hand side of the page even on legal. Has anyone experienced the same issue? We are required to submit timesheets to our customers withour invoices. I wish these were formated with the weeks in two one week rows rather than one two week period all the way accross. And that it fit on letter sized paper! What we currently ...

Save data before printing
Hello all, An acquiantence is programming in Excel 2003 and has a sheet where theuser enters receipt data. When he is done, he clicks a boton to copythe data from the sheet to another in tabular form withinthe same workbook. What he needs to do is to implement a lock so that the user can't print out the receipt until after he has clicked the boton. His button click event code is the following: Private Sub CommandButton1_Click() Application.ScreenUpdating = False 'Copy data to BD2 sheet Sheets("BD2").Unprotect With Sheets("BD2").Range("A1000&qu...

Execl print to fit paper
how do you set a group of cells to print to fit (maximize to one page size, normally 8 1/2 x 11) on one (and only one) page? Select the cells to be printed, then: <File> <PrintArea> <SetPrintArea> Then: <File> <PageSetUp> <Page> tab, Then click on: "Fit To" 1 page wide by 1 page tall, Then <OK>. -- HTH, RD --------------------------------------------------------------------------- Please keep all correspondence within the NewsGroup, so all may benefit ! --------------------------------------------------------------------------- "...

Printing updated customer information on a Receipt
Hello all, I modified the receipt to print the customer's total number of visits and total amount spent (both from the customer record) at the bottom of the receipt. The problem is that it is always printing the values as they stand before the last transaction. Example: if I create a new customer, do a tranaction ($20) and print the receipt, the number of visits and amount spent will show as zero. When I do a second transaction the receipt will print the values (visits 1, amount spent $20) as they stand at the end of the first transaction. Does anyone know how I can force the receip...

Checkbok & printing
I'd like to set up Excel to track my checkbook. I've got a spreadsheet made up that does that and let's me reconcile easily. Is there a way to take selected entries from the spreadsheet and have them "appear" in a check-style template and then print out the checks? I'm using Excel 2000 on Win XP Home SP 1. Thanks! <*((((><{ Fishy@Ocean.Net Hi Fishy, As a starting point see xlDynamic at: http://www.xldynamic.com/source/xld.xlFAQ0004.html --- Regards, Norman "<*(((><{" <Fishy@Ocean.Net> wrote in message news:c7nn72...

Macro Message Box
Hi, I am trying to build a macro for a histogram. When the macro is complete, I am asked "Histogram - Some data will be hidden by embedded chart(s)." I can click OK or cancel. How can I build my OK response into the macro so that I do not need to manually respond? Thank you for reviewing my question. Remove the MsgBox from the macro if it is unnecessary. -- HTH Bob "lahuwm" <lahuwm@discussions.microsoft.com> wrote in message news:ADD9273F-E393-4573-A3F5-BEEB344D21B0@microsoft.com... > Hi, I am trying to build a macro for a histogram. When...

Modified Report Not Printing Properly
GP 8.0, SQL We have two sites, each with its own vendors. We modified PO Blank Form so that it prints the correct site address in the ship to box. It works fine for one vendor, and prints the appropriate Site Address. However, for another vendor the Ship To is always blank. I cannot figure out why. I do not see any difference in how the vendors are set up. Any ideas for where I should look to resolve this problem? Thanks, Jason ...

Print multiple tabs on one page
How to print multiple tabs in excel onto one page in one print job? Tab1 and tab2 have different format and cannot be combined into one tab. Need to print the two worksheets one on top of each other is the same direction. Tried Report Manager but printed on two pieces of paper. Any suggestions? One way to accomplish something like this is to play around with "pictures". I'm on an XL97 machine now so, When you hold down <Shift> and hit <Edit>, you get a different dialog box .... one that contains "picture " options. So, select an entire sheet, or p...

Print a sheet for everday of the year
I need to print a sheet in Excel for every day of the year. How can I add the date automatically and print the sheet? Thanks, Jeff Hi Jeff Enter the first day of the year in A1 and run this macro to print Note it not print sunday Change PrintPreview to PrintOut if it is working Sub PrintCopies_ActiveSheet() 'this example not print sunday Dim mr As Integer mr = Year(Range("a1").Value) Do While Year(Range("a1").Value) = mr If Application.WorksheetFunction. _ Weekday(Range("a1").Value) <> 1 Then ActiveSheet.Pri...

Printing a Purchase Order to Multiple Destinations
Is it possible to print a PO to a text file on the local machine or network in addition to the local default printer? -- Pete P. It is possible to print a text file to any single location you want in addition to the local default printer. Our system currently prompts users requesting this information. Giving them their choice of 3 formats: Screen Printer File These can be selected in any combination but only one destination per format can be specified. I am hoping that this thread will explain how/if one could deliver one printed report to multiple printers. Eventually I would lik...

How do I do a Print Preview of the "Current / Active" page on a fo
Hello all I have attached a command button to a form and when I press the button it brings up a print preview of the report attached to the form. The problem is that it always shows Page 1 of the report as the default page. I can then only navigate to theother pages in the report by clicking the page arrow at the bottom of the report. How do I code the button so that when I click the button it shows a preview of the "current" record rather than always showing the first page of the report as the default page? I want to use this so that once people have completed filling inform...

Printing in Excel #2
I am printing a document in Excel with the gridlines bolded. However, when I Print the document it shifts the text in some cells down so they sit on the line. How do i fix this? Also just for reference i am using excel 2003 and we are using a windows 2000 print server. Not familiar with the problem. What font and pointsize. What printer. What happens if you choose Arial with pointsize of 10. What do you see in print preview. Do you have other choices for your print to printer. (file,print, name:) --- HTH, David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001] M...

Help with macro #4
I have a workbook with 2 worksheets. Each contains a column of part numbers with associated data. What I want to do is look at a part number in the second sheet and bring over some of the data for that part number from the first sheet. I know I can't use Vlookup across 2 sheets, and in any case I don't want to re-sort the data as required by vlookup. (its in date order, not part number order) I'm guessing this can only be done with a macro. Can anyone help? Thanks. Hi! >I know I can't use Vlookup across 2 sheets, and in any case I don't want to >re-sort the d...

Macro lovers
anyone like writing macros? or know where i could findout how to write one for this? im after one that will do the following, with a button; Sheet name = Totals unhide colum A Select Cells A2:J84 Select>Tools>Options>View>Showplaceholders Select A1>dropdown>Show hide colum A Select>Tools>Options>View>Hide all End or does anyone know if this will make my rows auto hide or show when data is on them? colum A has =IF(OR(B2="",B2=0),"Hide","Show) guess i can test it while i wait :) Thanks again everyone! Steve You like macros. Try recor...

Printing special characters
Hello In my Word 2003 document I have a number of special characters suchas the small 2 and small 3 used in maths equations (square root, cubic root, etc). Unfortunately, these print off as small cubes and I was hoping to rectify that, please. Best regards Steve Have you verified that the characters you're using exist in the font you're printing with? Do you use a font that was installed with your printer, that might be old enough that it doesn't include them? Alternatively, if you created your exponents with Superscript, have you verified that your print...

Macro --- Icon
Using Macro in excel for the first time and set up routine with an icon .. But only see a "Smilley Face" Icon for Macro and now have two macros with same Icon.... How do I add new Icon Image(s) to differentiate one Macro from the Other.... Lenny EggHeadCafe.com - .NET Developer Portal of Choice http://www.eggheadcafe.com Lenny Right click on any toolbar and select customise. While the dialog is showing right-click on your smiley face and select change button image. (If these don't take your fancy you can 'roll your own by selecting edit button image... or you ca...

Print Preview Problem
I am using modular forms in my Access 2K application. When I pull up a report in preview mode it displays behind any of the forms I might have open when I call the print prreview routine. Is there a way to bring this report up over the top of any open forms? Thanks in advance for any assistance you may be able to provide. ...

Printing in A5
Greetings from Downunder The items I need to print are similar to greeting cards -- A5 size in landscape orientation 21 cm wide & 14.7 cm high, side fold -- giving me four pages each 10.5 cm wide and 14.7 cm high. Creating this is no problem and all appears perfect right up to "print preview', even appearing correct in my printer's "print preview" screen. However, when I print, the contents of each page have changed their orientation to "portrait", and are 90 degrees out! Would anyone out there have a cure for this? Using XP Pro + SP 2, MS Office 2003...

Macro Question #13
Hello everyone, I have the following Code in Excel: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address <> "$G$4" Then Exit Sub Application.Goto Cells.Find(Target, after:=Target) End Sub I'm sure you are familiar with this??? Someone gave it to me her awhile ago. It just lets me type something in a cell and then it goe and finds whatever I typed on the worksheet. Okay, here is what I would like my code to do. Instead of going to th cell that contains that data, I would like it to return the value o the cell to the right of that cell in the cell und...