|
Option Explicit
Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
"OpenPrinterA" (ByVal pPrinterName As String, phPrinter _
As Long, ByVal pDefault As Long) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" ( _
ByVal hPrinter As Long) As Long
Private Declare Function DeviceCapabilities Lib "winspool.drv" _
Alias "DeviceCapabilitiesA" (ByVal lpsDeviceName As String, _
ByVal lpPort As String, ByVal iIndex As Long, lpOutput As Any, _
ByVal dev As Long) As Long
Const DC_BINS = 6
Const DC_BINNAMES = 12
Dim fachErsteSeite As Long
Dim fachFolgeSeite As Long
Private Sub UserForm_Initialize()
Dim sDeviceName As String
Dim sDevicePort As String
Dim hPrinter As Long
Dim bins As Long
Dim binList As String
Dim binNum() As Integer
Dim binString As String
Dim x As Integer
Dim strListe() As String
DruckerNameErmitteln sDeviceName, sDevicePort
If OpenPrinter(sDeviceName, hPrinter, 0) <> 0 Then
Label1.Caption = " " & ActivePrinter
ListBox1.Clear
ListBox1.ColumnCount = 2
ListBox2.Clear
ListBox2.ColumnCount = 2
bins = DeviceCapabilities(sDeviceName, sDevicePort, _
DC_BINS, ByVal vbNullString, 0)
ReDim binNum(1 To bins)
bins = DeviceCapabilities(sDeviceName, sDevicePort, _
DC_BINS, binNum(1), 0)
binList = String$(24 * bins, 0)
bins = DeviceCapabilities(sDeviceName, sDevicePort, _
DC_BINNAMES, ByVal binList, 0)
ReDim strListe(1 To bins, 2)
For x = 1 To bins
binString = Mid(binList, 24 * (x - 1) + 1, 24)
binString = Left(binString, InStr(1, binString, Chr(0)) - 1)
strListe(x, 0) = binString
strListe(x, 1) = (binNum(x))
Next x
ClosePrinter (hPrinter)
ListBox1.List() = strListe
ListBox2.List() = strListe
Call PapierzufuhrErmitteln
Else
Label1.Caption = ActivePrinter & " nicht ansprechbar!"
ListBox1.Clear
ListBox2.Clear
cmdUebernehmen.Enabled = False
End If
End Sub
Private Sub DruckerNameErmitteln(druckerName As String, _
druckerPort As String)
Dim sString As String
Const suchText As String = " on "
sString = ActivePrinter
druckerName = Left(sString, InStr(1, sString, suchText) - 1)
druckerPort = Right(sString, Len(sString) - Len(druckerName) - _
Len(suchText))
End Sub
Private Sub PapierzufuhrErmitteln()
Dim x As Integer
fachErsteSeite = ActiveDocument.PageSetup.FirstPageTray
If fachErsteSeite = 0 Then
ListBox1.ListIndex = 0
Else
For x = 0 To ListBox1.ListCount - 1
If ListBox1.List(x, 1) = fachErsteSeite Then
ListBox1.ListIndex = x
Exit For
End If
Next x
End If
fachFolgeSeite = ActiveDocument.PageSetup.OtherPagesTray
If fachFolgeSeite = 0 Then
ListBox2.ListIndex = 0
Else
For x = 0 To ListBox1.ListCount - 1
If ListBox2.List(x, 1) = fachFolgeSeite Then
ListBox2.ListIndex = x
Exit For
End If
Next x
End If
End Sub
Private Sub ListBox1_Click()
If ListBox1.ListCount >= 1 Then
fachErsteSeite = ListBox1.List(ListBox1.ListIndex, 1)
End If
End Sub
Private Sub ListBox2_Click()
If ListBox2.ListCount >= 1 Then
fachFolgeSeite = ListBox2.List(ListBox2.ListIndex, 1)
End If
End Sub
Private Sub cmdUebernehmen_Click()
ActiveDocument.PageSetup.FirstPageTray = fachErsteSeite
ActiveDocument.PageSetup.OtherPagesTray = fachFolgeSeite
End Sub
|
|