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
| Option Explicit
Private Declare Function EnumPrintersA Lib "Winspool.drv" _
(ByVal flags As Long, ByVal Name As String, ByVal Level As Long, _
pPrinterEnum As Long, ByVal cdBuf As Long, _
pcbNeeded As Long, pcReturned As Long) As Long
Private Declare Function lstrlenA Lib "Kernel32" _
(ByVal lpString As Any) As Long
Private Declare Function lstrcpyA Lib "Kernel32" _
(ByVal lpString1 As String, ByVal lpString2 As Long) As Long
Private Function Imprimantes()
Dim PrinterEnum() As Long, Impr() As String
Dim Needed As Long, Returned As Long, i As Integer
EnumPrintersA 2, vbNullString, 5, 0, 0, Needed, 0
If Needed = 0 Then Exit Function
ReDim PrinterEnum(Needed / 4)
EnumPrintersA 2, vbNullString, 5, PrinterEnum(0), _
Needed, Needed, Returned
ReDim Impr(1 To Returned)
For i = 1 To Returned
Impr(i) = Space$(lstrlenA(PrinterEnum(i * 5 - 5)))
lstrcpyA Impr(i), PrinterEnum(i * 5 - 5)
Next i
Imprimantes = Impr
End Function
Sub ListeImprimante()
Dim Impr As Variant, i As Long
Cells.Clear
For Each Impr In Imprimantes
i = i + 1
Cells(i, 1) = Impr
Next Impr
End Sub |
Partager