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

VB 6 et antérieur Discussion :

[VB] Choisir l'imprimante en dur


Sujet :

VB 6 et antérieur

  1. #1
    Membre averti Avatar de Vince
    Profil pro
    Inscrit en
    Mars 2002
    Messages
    369
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 369
    Points : 366
    Points
    366
    Par défaut [VB] Choisir l'imprimante en dur
    Bonjour,

    Je cherche à imprimer dans VB à partir d'une imprimante que j'ai défini en dur dans mon code.
    Ansi je testerai s'il l'imprimante existe, si elle existe je lance l'impression...
    Comment faire ???


    Merci d'avance de votre aide !!!

  2. #2
    Inactif  
    Avatar de ouskel'n'or
    Profil pro
    Inscrit en
    Février 2005
    Messages
    12 464
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 12 464
    Points : 15 543
    Points
    15 543
    Par défaut
    En VBA, j'ai ça

    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 SélectionnerUneImprimante()
    MonImprimante = "\\OLAN\CCACX010 sur Ne05:"   '/réseau
    Application.ActivePrinter = MonImprimante
    ActiveSheet.PrintOut
     
    'Ou...
     
    'Identifier l'imprimante ***********************
    MonImprimante = "?????" ' Nom de l'imprimante souhaitée
    With Application
          ImprimanteActive = .ActivePrinter
    End With
    If Trim(UCase(MonImprimante)) <> Trim(UCase(ImprimanteActive)) Then
           MsgBox "c'est pas la bonne imprimante"
           'Tu fais ce que tu as à faire...
    End If
    End Sub
    Si ça peut te servir...

    A+

  3. #3
    Membre averti Avatar de Vince
    Profil pro
    Inscrit en
    Mars 2002
    Messages
    369
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 369
    Points : 366
    Points
    366
    Par défaut
    Merci pour ton aide ouskel'n'or, mais moi il me le faut en VB tout court
    !

    J'ai trouvé ça mais je ne m'en sort pas avec
    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
    Option Explicit 
     
    Private Const CCHDEVICENAME = 32 
    Private Const CCHFORMNAME = 32 
    Private Const PD_RETURNDC = &H100 
    Private Const PD_RETURNIC = &H200 
    Private Const NULL_PTR = 0& 
     
    Private Type DEVMODE 
            dmDeviceName As String * CCHDEVICENAME 
            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 * CCHFORMNAME 
            dmUnusedPadding As Integer 
            dmBitsPerPel As Long 
            dmPelsWidth As Long 
            dmPelsHeight As Long 
            dmDisplayFlags As Long 
            dmDisplayFrequency As Long 
    End Type 
    Private Type DEVNAMES 
            wDriverOffset As Integer 
            wDeviceOffset As Integer 
            wOutputOffset As Integer 
            wDefault As Integer 
    End Type 
    'renommé pour différencier avec la fonction PrintDlg 
    Private Type InformationImprimante ' PRINTDLG 
        lStructSize As Long 
        hwndOwner As Long 
        hDevMode As Long 
        hDevNames As Long 
        hdc As Long 
        flags As Long 
        nFromPage As Integer 
        nToPage As Integer 
        nMinPage As Integer 
        nMaxPage As Integer 
        nCopies As Integer 
        hInstance As Long 
        lCustData As Long 
        lpfnPrintHook As Long 
        lpfnSetupHook As Long 
        lpPrintTemplateName As String 
        lpSetupTemplateName As String 
        hPrintTemplate As Long 
        hSetupTemplate As Long 
    End Type 
     
    Private Declare Function PrintDlg Lib "comdlg32.dll" Alias "PrintDlgA" (pPrintdlg As InformationImprimante) As Long 
     
    Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long 
    Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long 
    Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long 
    Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long 
     
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long) 
     
    Private Sub cmdImprimer_Click() 
        Dim retourAPI As Long 
        Dim imprimanteSelectionne As InformationImprimante 
        Dim infoDevice As DEVMODE 
        Dim nomImprimante As String 
        Dim adresseStructureDEVMODE As Long 
        Dim imprimante As Printer 
        ' 
        On Error GoTo Err_Impression 
        ' 
        retourAPI = 0 
        ' 
        ' Initialisation de la structure d'échange 
        ' 
        imprimanteSelectionne.lStructSize = Len(imprimanteSelectionne) 
        imprimanteSelectionne.hDevMode = NULL_PTR 
        imprimanteSelectionne.hDevNames = NULL_PTR 
        imprimanteSelectionne.flags = PD_RETURNIC 
     
        ' Ouverture du CommonDialog via l'API PrintDlg 
        retourAPI = PrintDlg(imprimanteSelectionne) 
     
        ' Retour de l'API si Annulé -> Retour = 0 
        Select Case retourAPI 
     
        Case 0 'Abandon 
            Exit Sub 
        Case 1 ' OK 
            adresseStructureDEVMODE = GlobalLock(imprimanteSelectionne.hDevMode) 
            Call CopyMemory(infoDevice, ByVal adresseStructureDEVMODE, Len(infoDevice)) 
     
            nomImprimante = Left(infoDevice.dmDeviceName, InStr(1, infoDevice.dmDeviceName, Chr(NULL_PTR)) - 1) 
            For Each imprimante In Printers 
                If nomImprimante = imprimante.DeviceName Then 
                    Set Printer = imprimante 
                    Exit For 
                End If 
            Next 
        Case Else 'an error occured 
            MsgBox ("Erreur inatendue") 
            Exit Sub 
        End Select 
        ' 
        ' Affectation des paramètres de configuration de l'imprimante 
        Printer.Orientation = infoDevice.dmOrientation 
        Printer.Copies = infoDevice.dmCopies 
        ' etc... 
        ' 
        ' Ecriture du texte en utilisant l'objet Printer 
        Printer.Print "OK" 
        RichTextBox1.SelPrint Printer.hdc 
        Printer.EndDoc 
     
        Exit Sub 
     
    Err_Impression: 
     
    End Sub

  4. #4
    Membre averti Avatar de Vince
    Profil pro
    Inscrit en
    Mars 2002
    Messages
    369
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 369
    Points : 366
    Points
    366
    Par défaut
    Bon j'ai trouvé comment choisir en dur l'imprimante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    nomImprimante = "Generic PostScript Printer"
     
            For Each imprimante In Printers
                If nomImprimante = imprimante.DeviceName Then
                    Set Printer = imprimante
                    Exit For
                End If
            Next
    Maintenant je cherche un moyen d'imprimer un fichier indépendant avec l'objet Printer

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Choisir l'imprimante sans changer celle par défaut
    Par Shiven dans le forum VBA Word
    Réponses: 9
    Dernier message: 26/09/2007, 15h02
  2. Réponses: 3
    Dernier message: 22/05/2007, 09h33
  3. [Etat]Choisir une imprimante
    Par libremax dans le forum IHM
    Réponses: 1
    Dernier message: 04/04/2007, 15h49
  4. Réponses: 20
    Dernier message: 04/04/2006, 08h16
  5. [Report Buider] choisir l'imprimante
    Par shawinnigan dans le forum Autres outils décisionnels
    Réponses: 2
    Dernier message: 11/08/2004, 15h43

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