IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Impression par macro en Recto-Verso


Sujet :

Macros et VBA Excel

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    27
    Détails du profil
    Informations personnelles :
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Mars 2010
    Messages : 27
    Points : 18
    Points
    18
    Par défaut Impression par macro en Recto-Verso
    Bonjour à tous,

    Je recherche une solution pour imprimer en recto-verso via une macro une feuille excel.

    J'ai fait des recherches dans les forums et je n'est pas trouvé de solution.

    L'enregistreur automatique de macro ne récupère pas ce paramètre pour imprimé en recto verso.

    Existe t il une solution en VB pour ce problème.

    Merci

  2. #2
    Expert éminent sénior
    Homme Profil pro
    aucune
    Inscrit en
    Septembre 2011
    Messages
    8 203
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : aucune

    Informations forums :
    Inscription : Septembre 2011
    Messages : 8 203
    Points : 14 354
    Points
    14 354
    Par défaut
    Bonjour,

    Tu peux utiliser la commande suivante pour choisir et configurer ton imprimante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Application.Dialogs(xlDialogPrinterSetup).Show
    Cordialement.

    Daniel

    La plus perdue de toutes les journées est celle où l'on n'a pas ri. Chamfort

  3. #3
    Membre chevronné Avatar de ZebreLoup
    Homme Profil pro
    Ingénieur Financier
    Inscrit en
    Mars 2010
    Messages
    994
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur Financier
    Secteur : Finance

    Informations forums :
    Inscription : Mars 2010
    Messages : 994
    Points : 2 131
    Points
    2 131
    Par défaut
    Sinon j'ai trouvé ça sur le site de Microsoft :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    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
    « Compter en octal, c’est comme compter en décimal, si on n’utilise pas ses pouces » - Tom Lehrer
    « Il est assez difficile de trouver une erreur dans son code quand on la cherche. C’est encore bien plus dur quand on est convaincu que le code est juste. » - Steve McConnell

  4. #4
    Expert éminent sénior
    Homme Profil pro
    aucune
    Inscrit en
    Septembre 2011
    Messages
    8 203
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : aucune

    Informations forums :
    Inscription : Septembre 2011
    Messages : 8 203
    Points : 14 354
    Points
    14 354
    Par défaut
    Tu peux aussi créer une imprimante identique à l'imprimante initiale dans le panneau de configuratiion, Gestionnaire d'imprimantes. Tu modifies la propriété "recto-verso". Utilise ensuite le code suivant pour définir l'imprimante par défaut (exécuter la macro "test" en indiquant le nom de l'imprimante) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    Sub Imprimante_Par_Defaut(Imprimante As String)
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colInstalledPrinters = objWMIService.ExecQuery _
        ("Select * from Win32_Printer Where Name = '" & Imprimante & "'")
    For Each objPrinter In colInstalledPrinters
        objPrinter.SetDefaultPrinter
    Next
    End Sub
     
    Private Sub test()
    Dim Imprimante As String
    'Nom de l'imprimante
    Imprimante = "Microsoft XPS Document Writer"
    Imprimante_Par_Defaut Imprimante
    End Sub
    Cordialement.

    Daniel

    La plus perdue de toutes les journées est celle où l'on n'a pas ri. Chamfort

Discussions similaires

  1. [XL-2010] Comment bloquer l'impression recto verso via une macro
    Par nejorqui dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 23/06/2015, 20h17
  2. [WD-2010] Impression Recto-Verso par défaut
    Par Goose- dans le forum Word
    Réponses: 4
    Dernier message: 27/05/2013, 10h29
  3. Macros Impression recto/verso
    Par OmarB dans le forum Word
    Réponses: 6
    Dernier message: 16/02/2008, 18h54
  4. Impression document Word en recto-verso
    Par wxcnbv dans le forum VBA Word
    Réponses: 4
    Dernier message: 07/02/2008, 09h41
  5. [CR8.5] Impression Recto verso
    Par L.nico dans le forum SAP Crystal Reports
    Réponses: 2
    Dernier message: 25/11/2003, 16h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo