ExcelでDeviceCapabilitie
ExcelでAPIを使用して、用紙番号を取得したいと考えています。
Excel2007(OS Win7)上では取得できるのですがExcel2000(OS WinXP)上ではエラー。
GetPrinterNameAndPortで、『 on 』と『 の 』がバージョンによって変えてもダメでした。アドバイスよろしくお願い致します。
Private Declare Function DeviceCapabilities Lib "winspool.drv" Alias "DeviceCapabilitiesA" (ByVal pDevice As String, ByVal pPort As String, ByVal fwCapability As Long, pOutput As Any, pDevMode As Any) As Long
Private Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Const DC_PAPERNAMES = 16
Private Const DC_PAPERS = 2
Private Const DC_BINNAMES = 12
Private Const DC_BINS = 6
Private Const DEFAULT_VALUES = 0
Sub Numbertest()
Dim strDeviceName As String
Dim strDevicePort As String
Dim lngPaperCount As Long
Dim bytPaper() As Byte
Dim strPaperName As String * 64
Dim lngCounter As Long
Dim aintNubytPaper() As Integer
Dim lngRet As Long
GetPrinterNameAndPort strDeviceName, strDevicePort
lngPaperCount = DeviceCapabilities(strDeviceName, strDevicePort, DC_PAPERNAMES, ByVal vbNullString, ByVal vbNullString)
ReDim bytPaper(64 - 1, lngPaperCount - 1)
ReDim aintNubytPaper(1 To lngPaperCount)
DeviceCapabilities strDeviceName, strDevicePort, DC_PAPERNAMES, bytPaper(0, 0), ByVal vbNullString
lngRet = DeviceCapabilities(strDeviceName, strDevicePort, DC_PAPERS, aintNubytPaper(1), ByVal vbNullString)
For lngCounter = 0 To lngPaperCount - 1
MoveMemory ByVal strPaperName, bytPaper(0, lngCounter), 64
MsgBox aintNubytPaper(lngCounter + 1) & " & " & Left(strPaperName, InStr(strPaperName, vbNullChar) - 1)
Next lngCounter
End Sub
Private Sub GetPrinterNameAndPort(printerName As String, printerPort As String)
Dim sString As String
Const searchText As String = " on " ←使い分け
' Const searchText As String = " の "
sString = ActivePrinter
printerName = Left(sString, InStr(1, sString, searchText) - 1)
printerPort = Right(sString, Len(sString) - Len(printerName) - Len(searchText))
End Sub
お礼
パソコンのトラブルで お礼が遅くなりました。 アドバイス ありがとうございます★