Sub PrinterDefault() Dim Text$, i%, j%, tmp, PrnList As Object, PrnDef$, u% PrnDef = Application.ActivePrinter Text = "Sélectionnez l'imprimante par défaut voulue" & vbLf _ & "(Entrez le numéro de ligne correspondant) !" & vbLf & vbLf With CreateObject("WScript.Network") Set PrnList = .EnumPrinterConnections j = PrnList.Count For i = 0 To j - 1 Step 2 Text = Text & (i / 2) & " -> " Text = Text & PrnList(i + 1) If InStr(1, PrnDef, PrnList(i + 1)) Then Text = Text & " (par défaut)": u = i / 2 End If Text = Text & vbLf Next Again: tmp = InputBox(Text, "Selection imprimante par default", u) If tmp = "" Then GoTo Fin tmp = CInt(tmp) If tmp < 0 Or tmp > (j / 2) - 1 Then GoTo Again .SetDefaultPrinter PrnList(tmp * 2 + 1) End With Fin: Set PrnList = Nothing End Sub 'MP
isabelle
BOnjour,
Je souhaiterais changer l'imprimante et ne pas prendre celle par défaut pour imprimer un document word que j'ai lancé depuis une macro excel
Sub PrinterDefault()
Dim Text$, i%, j%, tmp, PrnList As Object, PrnDef$, u%
PrnDef = Application.ActivePrinter
Text = "Sélectionnez l'imprimante par défaut voulue" & vbLf _
& "(Entrez le numéro de ligne correspondant) !" & vbLf & vbLf
With CreateObject("WScript.Network")
Set PrnList = .EnumPrinterConnections
j = PrnList.Count
For i = 0 To j - 1 Step 2
Text = Text & (i / 2) & " -> "
Text = Text & PrnList(i + 1)
If InStr(1, PrnDef, PrnList(i + 1)) Then
Text = Text & " (par défaut)": u = i / 2
End If
Text = Text & vbLf
Next
Again:
tmp = InputBox(Text, "Selection imprimante par default", u)
If tmp = "" Then GoTo Fin
tmp = CInt(tmp)
If tmp < 0 Or tmp > (j / 2) - 1 Then GoTo Again
.SetDefaultPrinter PrnList(tmp * 2 + 1)
End With
Fin: Set PrnList = Nothing
End Sub 'MP
isabelle
BOnjour,
Je souhaiterais changer l'imprimante et ne pas prendre
celle par défaut pour imprimer un document word que j'ai
lancé depuis une macro excel
Sub PrinterDefault() Dim Text$, i%, j%, tmp, PrnList As Object, PrnDef$, u% PrnDef = Application.ActivePrinter Text = "Sélectionnez l'imprimante par défaut voulue" & vbLf _ & "(Entrez le numéro de ligne correspondant) !" & vbLf & vbLf With CreateObject("WScript.Network") Set PrnList = .EnumPrinterConnections j = PrnList.Count For i = 0 To j - 1 Step 2 Text = Text & (i / 2) & " -> " Text = Text & PrnList(i + 1) If InStr(1, PrnDef, PrnList(i + 1)) Then Text = Text & " (par défaut)": u = i / 2 End If Text = Text & vbLf Next Again: tmp = InputBox(Text, "Selection imprimante par default", u) If tmp = "" Then GoTo Fin tmp = CInt(tmp) If tmp < 0 Or tmp > (j / 2) - 1 Then GoTo Again .SetDefaultPrinter PrnList(tmp * 2 + 1) End With Fin: Set PrnList = Nothing End Sub 'MP
isabelle
BOnjour,
Je souhaiterais changer l'imprimante et ne pas prendre celle par défaut pour imprimer un document word que j'ai lancé depuis une macro excel