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
| Option Explicit
Private Declare Function GetProfileSection& Lib "kernel32" Alias "GetProfileSectionA" ( _
ByVal lpAppName As String, _
ByVal lpReturnedString As String, _
ByVal lngSize As Long)
Private Function ListeImprimantes() As Variant
Dim sA As String, rep As Long, cpt As Long, pos As Long, T() As String
sA = Space(2048)
rep = GetProfileSection("devices", sA, 2048)
If rep > 0 Then
sA = Trim$(Replace(sA, Chr(0), ""))
Do Until sA = ""
cpt = cpt + 1
ReDim Preserve T(1 To 2, 1 To cpt)
pos = InStr(1, sA, "=") - 1
T(1, cpt) = Mid$(sA, 1, pos)
pos = InStr(1, sA, ",") + 1
T(2, cpt) = Mid(sA, pos, InStr(1, sA, ":") + 1 - pos)
sA = Mid$(sA, InStr(1, sA, ":") + 1)
Loop
End If
ListeImprimantes = Application.WorksheetFunction.Transpose(T)
End Function
Sub Test_Impression()
Dim TabImprimantes As Variant
Dim i As Long
TabImprimantes = ListeImprimantes
For i = 1 To UBound(TabImprimantes, 1)
If TabImprimantes(i, 1) = "PDFCreator" Then
Application.ActivePrinter = TabImprimantes(i, 1) & " sur " & TabImprimantes(i, 2)
Exit For
End If
Next i
End Sub
Sub Test_Liste_Imprimantes_Ports()
Dim sA As String, rep As Long, cpt As Long, pos As Long, T() As String
sA = Space(2048)
rep = GetProfileSection("devices", sA, 2048)
If rep > 0 Then
Feuil1.Cells.Clear
sA = Trim$(Replace(sA, Chr(0), ""))
Do Until sA = ""
cpt = cpt + 1
ReDim Preserve T(1 To 2, 1 To cpt)
pos = InStr(1, sA, "=") - 1
T(1, cpt) = Mid$(sA, 1, pos)
pos = InStr(1, sA, ",") + 1
T(2, cpt) = Mid$(sA, pos, InStr(1, sA, ":") + 1 - pos)
sA = Mid$(sA, InStr(1, sA, ":") + 1)
With Feuil1
.Cells(cpt, 1) = T(1, cpt)
.Cells(cpt, 2) = T(2, cpt)
End With
Loop
End If
End Sub |
Partager