You are here:Home-Domande su Excel VBA e MACRO-Stampare un file excel in fronte-retro con codice vba.
Stampare un file excel in fronte-retro con codice vba.2019-10-30T08:30:36+01:00

Home Forum Domande su Excel VBA e MACRO Stampare un file excel in fronte-retro con codice vba.

Taggato: 

Visualizzazione 12 filoni di risposte
  • Autore
    Post
    • AvatarMisterExcel
      Partecipante
        Post totali: 26

        Buongiorno ragazzi.

        Vi chiedo un aiuto per un semplice problema che non riesco a risolvere.

        Ho un foglio excel che andrebbe stampato su due pagine. Chiedo, se possibile, un codice scritto in vba che, attraverso un pulsante, mi stampi il file in fronte retro.

        Ho cercato in rete, ma non ho trovato una soluzione.

        Grazie in anticipo.

      • BySalvBySalv
        Amministratore del forum
          Post totali: 759

          Ciao che significa Fronte/Retro, è la stampante che deve essere settata.

          se poi vuoi che essendo i dati più lunghi della pagina su un secondo foglio ti riporti le intestazioni allora devi impostare la pagina.

          spiega meglio il problema.

          Ciao By Sal (8-D

           

           

           

          Ciao By Sal (8-)
          se ti piace la soluzione aiuta a sostenere il Forum con una DONAZIONE a piacere, Grazie

        • AvatarMisterExcel
          Partecipante
            Post totali: 26

            Grazie By Sal per la tempestiva risposta.

            Il pulsante che avvia la stampa si trova sulla form. Se clicco sul pulsante, parte la stampa immediata che avviene su due fogli.

            Io vorrei che, cliccando sul pulsante “STAMPA”, la stampa avvenga sullo stesso foglio (fronte retro) e questo, senza dovere andare prima sulle impostazioni della stampa (anteprima di stampa-stampa fronte retro).

            In pratica non devo andare ad impostare la modalità di stampa fronte-retro ogni volta che devo stampare il file.

            Spero di essere stato più chiaro.

            Grazie.-

             

          • BySalvBySalv
            Amministratore del forum
              Post totali: 759

              Ciao, ho fatto una ricerca ed ho trovato questo

              https://www.excelvba.it/Forum/story/Excel_e_gli_applicativi_Office/Stampa_fronteretro.html

              però non ci ho capito molto, perche non ho trovato i vari comandi che dice.

              altre discussioni dicono di smanettare in Excel con la proprietà Stampante

              ed altre ancora dicono che excel non gestisce la stampa fronte retro.

              non uso la stampante, quindi non saprei cosa proporti.

              Ciao By Sal (8-D

               

               

               

              Ciao By Sal (8-)
              se ti piace la soluzione aiuta a sostenere il Forum con una DONAZIONE a piacere, Grazie

            • AvatarMisterExcel
              Partecipante
                Post totali: 26

                Purtroppo il mio timore era che non fosse previsto in VBA un codice che facesse quello che ho richiesto.

                Tu mi hai dato la conferma.

                Ti ringrazio comunque.

                Ciao By Sal

              • AvatarMisterExcel
                Partecipante
                  Post totali: 26

                  Ho continuato a cercare in rete e sembra che sia possibile risolvere il problema intervenendo sulle API.

                  Magari qualcuno esperto del gruppo potrà aiutarmi… :cry:

                • BySalvBySalv
                  Amministratore del forum
                    Post totali: 759

                    Ciao mi dai il link dell’articolo cosi lo leggo e cerco di capire cosa intende.

                    Ciao (8-D

                     

                     

                     

                    Ciao By Sal (8-)
                    se ti piace la soluzione aiuta a sostenere il Forum con una DONAZIONE a piacere, Grazie

                  • AvatarMisterExcel
                    Partecipante
                      Post totali: 26

                      Ciao BySal.

                      Questo è il codice:
                      <ul class=”topiclist forums” style=”margin: 0px; padding: 0px; list-style-type: none; background: url(‘gradient.gif’) 0px 0px repeat-x #eef5f9; font-size: 12px; color: #536482; font-family: Verdana, Helvetica, Arial, sans-serif;”>
                      <li class=”row1″ style=”margin: 0px; padding: 0px; border-top: 1px solid #ffffff; border-bottom: 1px solid #00608f; font-size: 1.1em; color: #1e1e96; display: block; list-style-type: none;”><center style=”margin: 0px; padding: 0px;”>
                      <table style=”margin: 0px; padding: 0px;” border=”0″ bgcolor=”#ffff99″>
                      <tbody style=”margin: 0px; padding: 0px;”>
                      <tr style=”margin: 0px; padding: 0px;”>
                      <td class=”tdleft” style=”margin: 0px; padding: 0px; font-family: verdana; font-size: 11px; font-weight: lighter; word-break: break-all; overflow-wrap: break-word;”>
                      <pre style=”margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap;”>Aggiungere un modulo BAS standard al progetto.
                      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 default properties
                      ‘ of the printer driver.

                      ‘ Returns: True on success and False on error. An error also

                      ‘ displays a message box. This message box is displayed for information
                      ‘ only. You must 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 sPrinterName 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_ALL_ACCESS
                      nRet = OpenPrinter(sPrinterName, 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, sPrinterName, 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, sPrinterName, _
                      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, sPrinterName, _
                      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

                      Aggiungere un controllo Pulsante di comando a Form1.
                      Aggiungere l’esempio di codice riportato di seguito alla finestra del codice per Form1.

                      Option Explicit
                      Private Sub Command1_Click()
                      Dim oWord As Object
                      Dim oDoc As Object

                      Set oWord = CreateObject(“Word.application”)

                      oWord.Visible = True

                      Set oDoc = oWord.Documents.Add
                      oDoc.Range.Select

                      oWord.Selection.TypeText “This is on page 1” & vbCr
                      oWord.Selection.InsertBreak 1
                      oWord.Selection.TypeText “This is page 2”

                      SetPrinterDuplex Printer.DeviceName, 2

                      oDoc.PrintOut Background:=False

                      SetPrinterDuplex Printer.DeviceName, 1

                      MsgBox “Print Done”, vbMsgBoxSetForeground

                      oDoc.Saved = True
                      oDoc.Close
                      Set oDoc = Nothing

                      oWord.Quit
                      Set oWord = Nothing
                      End Sub

                      Eseguire l’esempio.

                      Se la stampante supporta la stampa fronte retro, il documento di prova viene stampato su entrambi i lati della pagina
                      </td>
                      </tr>
                      </tbody>
                      </table>
                      </center>
                      <li class=”row1″ style=”margin: 0px; padding: 0px; border-top: 1px solid #ffffff; border-bottom: 1px solid #00608f; font-size: 1.1em; color: #1e1e96; display: block; list-style-type: none;”><span style=”font-family: monospace; font-size: 11px; white-space: pre-wrap; background-color: #ffff99;”>Aggiungere un controllo Pulsante di comando a Form1. Aggiungere l’esempio di codice riportato di seguito alla finestra del codice per Form1. Option Explicit Private Sub Command1_Click() Dim oWord As Object Dim oDoc As Object Set oWord = CreateObject(“Word.application”) oWord.Visible = True Set oDoc = oWord.Documents.Add oDoc.Range.Select oWord.Selection.TypeText “This is on page 1” & vbCr oWord.Selection.InsertBreak 1 oWord.Selection.TypeText “This is page 2” SetPrinterDuplex Printer.DeviceName, 2 oDoc.PrintOut Background:=False SetPrinterDuplex Printer.DeviceName, 1 MsgBox “Print Done”, vbMsgBoxSetForeground oDoc.Saved = True oDoc.Close Set oDoc = Nothing oWord.Quit Set oWord = Nothing End Sub Eseguire l’esempio. Se la stampante supporta la stampa fronte retro, il documento di prova viene stampato su entrambi i lati della pagina</span>

                    • AvatarMisterExcel
                      Partecipante
                        Post totali: 26

                        All’inizio va inserito questo codice:
                        <pre style=”margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; color: #1e1e96; font-size: 11px; background-color: #ffff99;”>Public Sub Stampanti_dia()
                        Sheets(“Lista d1”).PrintOut From:=1, To:=2, Copies:=1, Collate:=True, _
                        IgnorePrintAreas:=False
                        End sub

                      • AvatarMisterExcel
                        Partecipante
                          Post totali: 26
                        • AvatarMisterExcel
                          Partecipante
                            Post totali: 26

                            <pre class=”bbcode_code” style=”margin-top: 0px; margin-bottom: 0px; padding: 6px; font-family: monospace; line-height: 12px; border: 1px inset; overflow: scroll; direction: ltr; background: repeat-x #f2f6f8; font-size: 12px; height: 432px;”><code style=”padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;”>QUESTO E’ UN’ALTRO CODICE TROVATO IN RETE….

                            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 structure
                            pSepFile As Long
                            pPrintProcessor As Long
                            pDatatype As Long
                            pParameters As Long
                            pSecurityDescriptor As Long ‘<<Pointer to SECURITY_DESCRIPTOR structure
                            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 Type PRINTER_INFO_9
                            pDevmode As Long ‘<<Pointer to DEVMODE structure
                            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 Integer, _
                            pPrinter As Byte, _
                            ByVal Command As Integer) As Long

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

                            Private Declare Function StrLen _
                            Lib “kernel32” _
                            Alias “lstrlenA” _
                            (ByVal lpString As Long) As Long

                            ‘ ==================================================================
                            ‘ SetPrinterDuplex.

                            ‘ Set the Duplex flag for the specified default properties
                            ‘ of the printer driver.

                            ‘ Returns: True on success and False on error. An error also

                            ‘ displays a message box. This message box is displayed for information
                            ‘ only. You must 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 sPrinterName As String, _
                            ByVal nDuplexSetting As Long) As Boolean

                            Dim hPrinter As Long
                            Dim pd As PRINTER_DEFAULTS
                            Dim pinfo As PRINTER_INFO_9
                            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(sPrinterName, 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, sPrinterName, 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, sPrinterName, _
                            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, sPrinterName, _
                            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, 9, 0, 0, nBytesNeeded)
                            If (nBytesNeeded = 0) Then GoTo cleanup

                            ReDim yPInfoMemory(nBytesNeeded + 100) As Byte

                            nRet = GetPrinter(hPrinter, 9, 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, 9, yPInfoMemory(0), 0)
                            If (nRet = 0) Then
                            ‘ MsgBox “Unable to set shared printer settings. Err number ” & Err.LastDllError
                            End If

                            SetPrinterDuplex = CBool(nRet)

                            If SetPrinterDuplex Then

                            End If

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

                            End Function

                            Public Sub PrintSingleSided()

                            Dim I As Long
                            Dim PrinterName As String
                            Dim RetVal As Variant

                            PrinterName = Application.ActivePrinter
                            I = InStr(1, PrinterName, ” on”)
                            If I > 0 Then PrinterName = Left(PrinterName, I – 1)

                            RetVal = SetPrinterDuplex(PrinterName, 1)

                            End Sub

                            Public Sub PrintTwoSidedBookStyle()

                            Dim I As Long
                            Dim PrinterName As String
                            Dim RetVal As Variant

                            PrinterName = Application.ActivePrinter
                            I = InStr(1, PrinterName, ” on”)
                            If I > 0 Then PrinterName = Left(PrinterName, I – 1)

                            RetVal = SetPrinterDuplex(PrinterName, 2)

                            End Sub

                            Public Sub PrintTwoSidedTabletStyle()

                            Dim I As Long
                            Dim PrinterName As String
                            Dim RetVal As Variant

                            PrinterName = Application.ActivePrinter
                            I = InStr(1, PrinterName, ” on”)
                            If I > 0 Then PrinterName = Left(PrinterName, I – 1)

                            RetVal = SetPrinterDuplex(PrinterName, 3)

                            End Sub

                          • BySalvBySalv
                            Amministratore del forum
                              Post totali: 759

                              Ciao ora vedo quello che hai scritto se riesco a ricavarne qualcosa.

                              ma mi dici la marca e modello della tua stampante.

                              Ciao By Sal (8-D

                               

                              Ciao By Sal (8-)
                              se ti piace la soluzione aiuta a sostenere il Forum con una DONAZIONE a piacere, Grazie

                            • AvatarMisterExcel
                              Partecipante
                                Post totali: 26

                                La marca della stampante è SAMSUNG ProXpress M3820ND.

                                Comunque nell’ultimo codice che ho inviato, c’è la possibilità di aprire una finestra con l’elenco delle stampanti in uso…

                            Visualizzazione 12 filoni di risposte
                            • Devi essere connesso per rispondere a questo topic.