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
| Option Explicit
Private Declare Function GetProfileSection& Lib "kernel32" Alias "GetProfileSectionA" ( _
ByVal lpAppName As String, _
ByVal lpReturnedString As String, _
ByVal lngSize As Long)
' Enumération des imprimantes et ports sur Feuil1
Sub ListeImprimantesPorts()
Dim sStr As String, rep As Long, iCpt As Long, iPos As Long, T() As String
sStr = Space(2048)
rep = GetProfileSection("devices", sStr, 2048)
If rep > 0 Then
Feuil1.Cells.Clear
Application.ScreenUpdating = False
sStr = Trim$(Replace(sStr, Chr(0), ""))
Do Until sStr = ""
iCpt = iCpt + 1
ReDim Preserve T(1 To 2, 1 To iCpt)
iPos = InStr(1, sStr, "=") - 1
T(1, iCpt) = Mid$(sStr, 1, iPos)
iPos = InStr(1, sStr, ",") + 1
T(2, iCpt) = Mid$(sStr, iPos, InStr(1, sStr, ":") + 1 - iPos)
sStr = Mid$(sStr, InStr(1, sStr, ":") + 1)
With Feuil1
.Cells(iCpt, 1) = T(1, iCpt)
.Cells(iCpt, 2) = T(2, iCpt)
End With
Loop
End If
Application.ScreenUpdating = True
End Sub |