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
| Option Explicit
Private Declare Function GetProfileSection& Lib "kernel32" Alias "GetProfileSectionA" ( _
ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal lngSize As Long)
Sub Liste_Ports_Imprimantes()
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