Afternoon everyone.
I have been trying to setup three different Printing Macros for our end users under Micrsofot Word.
What we have - Legal Print out, A4 Print out and Letter Print out. I made a custom toolbar for printing by using Macro, with each one set to certain page scale (i.e. Legal, A4 or Letter), certain tray and a printer.
The problem with the macros is that it prints the whole document once clicked instead of opening a Print Dialog box.
I re-wrote the macro like:
Although now when user clicks onto the Print button, it pops up the printer dialog box but it doesn't set the scale to Paper size = "Legal" even though I have mentioned it into the code.Code:ActivePrinter = "HP LaserJet 4050 Series PCL 6" Application.ActiveDocument.PageSetup.PaperSize = wdPaperLegal 'Application.Dialogs.Application.ActiveDocument.PageSetup.PaperSize = wdPaperLegal Application.Dialogs(wdDialogFilePrint).Show
I think what I need is to set the Printer.PageSize=wdPaperLegal but it doesn't work.
Could someone please help me in this situation?
Summary:
1: Set a printer to certain printer - which I have done
2: Set a printer to certain Page Size (Legal, A4, Letter) - Can't do for some reason
3: Set a printer to a certain Printer Tray - need to set to printer tray 2 but don't know how to do it.
Many thanks
Regards
Jehanzeb
Here is some code that I modified from from several sources
In another procedure you would call the SetPrinter Function, for exampleCode:Private Const DC_BINS = 6 Private Const DC_BINNAMES = 12 Private Declare Function DeviceCapabilities Lib "winspool.drv" _ Alias "DeviceCapabilitiesA" (ByVal lpDeviceName As String, _ ByVal lpPort As String, ByVal iIndex As Long, lpOutput As Any, _ ByVal dev As Long) As Long 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 Public Function GetBinNames() As Variant 'Code adapted from Microsoft KB article Q194789 'HOWTO: Determine Available PaperBins with DeviceCapabilities API Dim iBins As Long Dim ct As Long Dim sNamesList As String Dim sNextString As String Dim sPort As String Dim sCurrentPrinter As String Dim vBins As Variant '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 string to the right size to hold all the bin names '24 chars per name sNamesList = String(24 * iBins, 0) 'Load the string with the bin names iBins = DeviceCapabilities(sCurrentPrinter, sPort, _ DC_BINNAMES, ByVal sNamesList, 0) 'Set the array of bin names to the right size ReDim vBins(0 To iBins - 1) For ct = 0 To iBins - 1 'Get each bin name in turn and assign to the next item in the array sNextString = Mid(sNamesList, 24 * ct + 1, 24) vBins(ct) = Left(sNextString, InStr(1, sNextString, Chr(0)) - 1) Next ct 'Return the array to the calling routine GetBinNames = vBins End Function Private Function SetPrinter(TrayOption As String) As Long Dim vBinNumbers As Variant Dim ct As Long Dim iBins As Long Dim sBinName sBinName = GetBinNames vBinNumbers = GetBinNumbers For ct = 1 To UBound(sBinName) If InStr(sBinName(ct), TrayOption) > 0 Then SetPrinter = vBinNumbers(ct) Exit For End If Next ct End Function
Code:Private Sub TestPrinter() Dim lngTray As Long Dim PaperType As String 'make sure all the page setup options are correct On Error Resume Next lngTray = SetPrinter("Manual Feed") PaperType = "A4" 'check the page size based on the selected office With ActiveDocument.PageSetup .TopMargin = InchesToPoints(1.35) .BottomMargin = InchesToPoints(1) .LeftMargin = InchesToPoints(1) .RightMargin = InchesToPoints(1) .Gutter = InchesToPoints(0) .HeaderDistance = InchesToPoints(1.35) .FooterDistance = InchesToPoints(0.5) .DifferentFirstPageHeaderFooter = True End With If PaperType = "A4" Then With ActiveDocument.PageSetup .PageWidth = InchesToPoints(8.27) .PageHeight = InchesToPoints(11.69) End With Else With ActiveDocument.PageSetup .PageWidth = InchesToPoints(8.5) .PageHeight = InchesToPoints(11) End With End If Application.Dialogs(wdDialogFilePageSetup).Show Application.Dialogs(wdDialogFilePrint).Show End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks