Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word 2010 Printing Issue 1

Status
Not open for further replies.

bowlow77

Technical User
Aug 4, 2011
2
GB
Dear All,

I've been using this code snippet from MS in Office 2003, 2007 and its been working fine no issues. I've upgraded to Office 2010 and the code not working I think I've found why but can’t think of the way around it any help would be gladly received.

Line 3 sCurrentPrinter = Trim$(Left$(ActivePrinter, _
InStr(ActivePrinter, " on ")))
This in office 2003/2007 shows sCurrnetPrinter as the local printer yet in 2010 it does not the InStr(ActivePrinter, “ on “))) Functions shows the active printer and port “ on “ Port Name yet using 2010 it only shows the printer name.


Public Function GetBinNumbers() As Variant

'Code adapted from Microsoft KB article Q194789
'HOWTO: Determine Available PaperBins with DeviceCapabilities API
Dim iBins As Long
Dim iBinArray() As Integer
Dim sPort As String
Dim sCurrentPrinter As String
'Get the printer & port name of the current printer
sPort = Trim$(Mid$(ActivePrinter, InStrRev(ActivePrinter, " ") + 1))
sCurrentPrinter = Trim$(Left$(ActivePrinter, _
InStr(ActivePrinter, " on ")))
'Find out how many printer bins there are
iBins = DeviceCapabilities(sCurrentPrinter, sPort, _
DC_BINS, ByVal vbNullString, 0)
'Set the array of bin numbers to the right size
ReDim iBinArray(0 To iBins - 1)
'Load the array with the bin numbers
iBins = DeviceCapabilities(sCurrentPrinter, sPort, _
DC_BINS, iBinArray(0), 0)
'Return the array to the calling routine
GetBinNumbers = iBinArray
End Function

 
Think I may have sorted this myself, In word 2010 the .activeprinter only uses the printer name and the port is left off I added the following code it does rely on excel eing install but its a work around.

Public Function GetBinNumbers2010() As Variant

'Code adapted from Microsoft KB article Q194789
'HOWTO: Determine Available PaperBins with DeviceCapabilities API
'code added by SL to over come port removal from office 2010 active printer
Dim iBins As Long
Dim iBinArray() As Integer
Dim sPort As String
Dim sCurrentPrinter As String

'Code Added to Overcome Word 2010 Issue
Dim xlapp As Object
Dim bstartApp As Boolean
On Error Resume Next
Set xlapp = GetObject(, "excel.Application") 'note the call to excel
If Err Then
bstartApp = True
Set xlapp = CreateObject("excel.Application")
End If
On Error GoTo 0

'Get the printer & port name of the current printer
sPort = Trim$(Mid$(xlapp.ActivePrinter, InStrRev(xlapp.ActivePrinter, " ") + 1))
sCurrentPrinter = Trim$(Left$(xlapp.ActivePrinter, _
InStr(xlapp.ActivePrinter, " on ")))

'Find out how many printer bins there are
iBins = DeviceCapabilities(sCurrentPrinter, sPort, _
DC_BINS, ByVal vbNullString, 0)

'Set the array of bin numbers to the right size
ReDim iBinArray(0 To iBins - 1)

'Load the array with the bin numbers
iBins = DeviceCapabilities(sCurrentPrinter, sPort, _
DC_BINS, iBinArray(0), 0)

'Return the array to the calling routine
GetBinNumbers2010 = iBinArray

'Code Added to Overcome Word 2010 Issue
If bstartApp = True Then
xlapp.Quit
End If
Set xlapp = Nothing

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top