Prev: Get user input when document is created from template
Next: Non-modal forms and multiple documents
From: Vidhya on 21 Jan 2010 02:21 "Keith" wrote: > Alex, > > Thanks for the help. That worked the way I needed it to. The only problem I have now, is I need the binding to be changed. I need it to be changed to legal binding, that way when i flip the pages up, i can read then without having to turn the folder. Below is where it tells me to do that, I just can not figure out where or what to put in the code. Thanks, Keith > > ================================================================== > > ' SetPrinterDuplex > > ' > > ' Programmatically set the Duplex flag for the specified printer > > ' driver's default properties. > > ' > > ' Returns: True on success, False on error. (An error will also > > > > ' display a message box. This is done for informational value > > ' only. You should modify the code to support better error > > ' handling in your production application.) > > ' > > ' Parameters: > > ' sPrinterName - The name of the printer to be used. > > ' > > ' nDuplexSetting - One of the following standard settings: > > ' 1 = None > > ' 2 = Duplex on long edge (book) > > ' 3 = Duplex on short edge (legal) > > ' > > ' ================================================================== > > Public Function SetPrinterDuplex(ByVal s2ndFloorBinder As String, ByVal > nDuplexSetting As Long) As Boolean > > > > Dim hPrinter As Long > > Dim pd As PRINTER_DEFAULTS > > Dim pinfo As PRINTER_INFO_2 > > Dim dm As DEVMODE > > > > Dim yDevModeData() As Byte > > Dim yPInfoMemory() As Byte > > Dim nBytesNeeded As Long > > Dim nRet As Long, nJunk As Long > > > > On Error GoTo cleanup > > > > If (nDuplexSetting < 1) Or (nDuplexSetting > 3) Then > > MsgBox "Error: dwDuplexSetting is incorrect." > > Exit Function > > End If > > > "Alex Ivanov" wrote: > > > You need to call SetPrinterDuplex with fully qualified printer name > > somewhere before PrintOut, ie > > > > Sub PrintDuplex() > > Dim MyPrinter as String > > ' You might need to strip extra characters like " on NE03:" > > ' appended to the ActivePrinter property > > MyPrinter=Left(Word.ActivePrinter, InStr(1, Word.ActivePrinter, " ") - 1) > > SetPrinterDuplex MyPrinter, 2 > > ActiveDocument.PrintOut > > End Sub > > > > > > -- > > Please reply to NG only. The email address is not monitored. > > > > Alex. > > > > "Keith" <Keith(a)discussions.microsoft.com> wrote in message > > news:31A03FC8-21B5-4658-A08B-D22BF24859A5(a)microsoft.com... > > > I recorded a macro, and part of that macro is supposed to duplex my > > document when i print it. However, it does not. I got some code from > > Microsoft's website to help me with this, but there is something wrong with > > it somewhere. I belive that the problem exists when it asks me how i want > > to duplex it. The only problem is I dont know where to put the option in > > at. I will past the code below. any help would be greatful! > > > > > > Option Explicit > > > > > > Public Type PRINTER_DEFAULTS > > > > > > pDatatype As Long > > > pDevmode As Long > > > DesiredAccess As Long > > > End Type > > > > > > Public Type PRINTER_INFO_2 > > > pServerName As Long > > > pPrinterName As Long > > > pShareName As Long > > > pPortName As Long > > > pDriverName As Long > > > pComment As Long > > > pLocation As Long > > > pDevmode As Long ' Pointer to DEVMODE > > > pSepFile As Long > > > pPrintProcessor As Long > > > pDatatype As Long > > > pParameters As Long > > > pSecurityDescriptor As Long ' Pointer to SECURITY_DESCRIPTOR > > > Attributes As Long > > > > > > > > > Priority As Long > > > DefaultPriority As Long > > > StartTime As Long > > > UntilTime As Long > > > Status As Long > > > cJobs As Long > > > AveragePPM As Long > > > End Type > > > > > > Public Type DEVMODE > > > dmDeviceName As String * 32 > > > > > > dmSpecVersion As Integer > > > dmDriverVersion As Integer > > > dmSize As Integer > > > dmDriverExtra As Integer > > > dmFields As Long > > > dmOrientation As Integer > > > dmPaperSize As Integer > > > dmPaperLength As Integer > > > dmPaperWidth As Integer > > > dmScale As Integer > > > dmCopies As Integer > > > dmDefaultSource As Integer > > > dmPrintQuality As Integer > > > dmColor As Integer > > > dmDuplex As Integer > > > dmYResolution As Integer > > > dmTTOption As Integer > > > dmCollate As Integer > > > dmFormName As String * 32 > > > dmUnusedPadding As Integer > > > dmBitsPerPel As Integer > > > dmPelsWidth As Long > > > dmPelsHeight As Long > > > dmDisplayFlags As Long > > > dmDisplayFrequency As Long > > > dmICMMethod As Long > > > dmICMIntent As Long > > > dmMediaType As Long > > > dmDitherType As Long > > > dmReserved1 As Long > > > dmReserved2 As Long > > > End Type > > > > > > Public Const DM_DUPLEX = &H1000& > > > Public Const DM_IN_BUFFER = 8 > > > > > > Public Const DM_OUT_BUFFER = 2 > > > Public Const PRINTER_ACCESS_ADMINISTER = &H4 > > > Public Const PRINTER_ACCESS_USE = &H8 > > > Public Const STANDARD_RIGHTS_REQUIRED = &HF0000 > > > Public Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _ > > > PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE) > > > > > > Public Declare Function ClosePrinter Lib "winspool.drv" _ > > > (ByVal hPrinter As Long) As Long > > > Public Declare Function DocumentProperties Lib "winspool.drv" _ > > > Alias "DocumentPropertiesA" (ByVal hwnd As Long, _ > > > ByVal hPrinter As Long, ByVal pDeviceName As String, _ > > > ByVal pDevModeOutput As Long, ByVal pDevModeInput As Long, _ > > > ByVal fMode As Long) As Long > > > Public Declare Function GetPrinter Lib "winspool.drv" Alias _ > > > "GetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _ > > > pPrinter As Byte, ByVal cbBuf As Long, pcbNeeded As Long) As Long > > > Public Declare Function OpenPrinter Lib "winspool.drv" Alias _ > > > "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _ > > > pDefault As PRINTER_DEFAULTS) As Long > > > Public Declare Function SetPrinter Lib "winspool.drv" Alias _ > > > "SetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _ > > > pPrinter As Byte, ByVal Command As Long) As Long > > > > > > Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _ > > > (pDest As Any, pSource As Any, ByVal cbLength As Long) > > > > > > > > > ' ================================================================== > > > ' SetPrinterDuplex > > > ' > > > ' Programmatically set the Duplex flag for the specified printer > > > ' driver's default properties. > > > ' > > > ' Returns: True on success, False on error. (An error will also > > > > > > ' display a message box. This is done for informational value > > > ' only. You should modify the code to support better error > > > ' handling in your production application.) > > > ' > > > ' Parameters: > > > ' sPrinterName - The name of the printer to be used. > > > ' > > > ' nDuplexSetting - One of the following standard settings: > > > ' 1 = None > > > ' 2 = Duplex on long edge (book) > > > ' 3 = Duplex on short edge (legal) > > > ' > > > ' ================================================================== > > > Public Function SetPrinterDuplex(ByVal s2ndFloorBinder As String, ByVal > > nDuplexSetting As Long) As Boolean > > > > > > Dim hPrinter As Long > > > Dim pd As PRINTER_DEFAULTS > > > Dim pinfo As PRINTER_INFO_2 > > > Dim dm As DEVMODE > > > > > > Dim yDevModeData() As Byte > > > Dim yPInfoMemory() As Byte > > > Dim nBytesNeeded As Long > > > Dim nRet As Long, nJunk As Long > > > > > > On Error GoTo cleanup > > > > > > If (nDuplexSetting < 1) Or (nDuplexSetting > 3) Then > > > MsgBox "Error: dwDuplexSetting is incorrect." > > > Exit Function > > > End If > > > > > > pd.DesiredAccess = PRINTER_ALL_ACCESS > > > nRet = OpenPrinter(s2ndFloorBinder, hPrinter, pd) > > > If (nRet = 0) Or (hPrinter = 0) Then > > > If Err.LastDllError = 5 Then > > > MsgBox "Access denied -- See the article for more info." > > > Else > > > MsgBox "Cannot open the printer specified " & _ > > > "(make sure the printer name is correct)." > > > End If > > > Exit Function > > > End If > > > > > > nRet = DocumentProperties(0, hPrinter, s2ndFloorBinder, 0, 0, 0) > > > If (nRet < 0) Then > > > MsgBox "Cannot get the size of the DEVMODE structure." > > > GoTo cleanup > > > End If > > > > > > ReDim yDevModeData(nRet + 100) As Byte > > > nRet = DocumentProperties(0, hPrinter, s2ndFloorBinder, _ > > > VarPtr(yDevModeData(0)), 0, DM_OUT_BUFFER) > > > If (nRet < 0) Then > > > MsgBox "Cannot get the DEVMODE structure." > > > GoTo cleanup > > > End If > > > > > > Call CopyMemory(dm, yDevModeData(0), Len(dm)) > > > > > > If Not CBool(dm.dmFields And DM_DUPLEX) Then > > > MsgBox "You cannot modify the duplex flag for this printer " & _ > > > "because it does not support duplex or the driver " & _ > > > "does not support setting it from the Windows API." > > > GoTo cleanup > > > End If > > > > > > dm.dmDuplex = nDuplexSetting > > > Call CopyMemory(yDevModeData(0), dm, Len(dm)) > > > > > > nRet = DocumentProperties(0, hPrinter, s2ndFloorBinder, _ > > > VarPtr(yDevModeData(0)), VarPtr(yDevModeData(0)), _ > > > DM_IN_BUFFER Or DM_OUT_BUFFER) > > > > > > If (nRet < 0) Then > > > MsgBox "Unable to set duplex setting to this printer." > > > GoTo cleanup > > > End If > > > > > > Call GetPrinter(hPrinter, 2, 0, 0, nBytesNeeded) > > > If (nBytesNeeded = 0) Then GoTo cleanup > > > > > > ReDim yPInfoMemory(nBytesNeeded + 100) As Byte > > > > > > nRet = GetPrinter(hPrinter, 2, yPInfoMemory(0), nBytesNeeded, nJunk) > > > If (nRet = 0) Then > > > MsgBox "Unable to get shared printer settings." > > > GoTo cleanup > > > End If > > > > > > Call CopyMemory(pinfo, yPInfoMemory(0), Len(pinfo)) > > > pinfo.pDevmode = VarPtr(yDevModeData(0)) > > > pinfo.pSecurityDescriptor = 0 > > > Call CopyMemory(yPInfoMemory(0), pinfo, Len(pinfo)) > > > > > > nRet = SetPrinter(hPrinter, 2, yPInfoMemory(0), 0) > > > If (nRet = 0) Then > > > MsgBox "Unable to set shared printer settings." > > > End If > > > > > > SetPrinterDuplex = CBool(nRet) > > > > > > cleanup: > > > If (hPrinter <> 0) Then Call ClosePrinter(hPrinter) > > > > > > End Function > > > > > > Sub binder() > > > ' > > > ' binder Macro > > > ' Macro recorded 7/12/2004 by Keith R. Sylvester > > > ' > > > With ActiveDocument.PageSetup > > > .LineNumbering.Active = False
From: Vidhya on 21 Jan 2010 02:25 I have the same query as Keith. I worked over the coding. But the printing doesnt take any effect on duplex. I work on the network over a shared printer. It gives the messate 'Unable to set shared printer settings'. Why is that? Isnt the same like changing the 'Duplex' value to 2/3 in the Printing preferences? thanks in advance
From: Jonathan West on 21 Jan 2010 06:43 "Vidhya" <Vidhya(a)discussions.microsoft.com> wrote in message news:E9D346F1-FC64-439E-8FE8-FB62CB127E66(a)microsoft.com... >I have the same query as Keith. I worked over the coding. But the printing > doesnt take any effect on duplex. I work on the network over a shared > printer. It gives the messate 'Unable to set shared printer settings'. Why > is > that? Isnt the same like changing the 'Duplex' value to 2/3 in the > Printing > preferences? > > thanks in advance You'll need a locally-installer printer driver for that code to work. -- Regards Jonathan West
From: Vidhya on 21 Jan 2010 20:26 But I need the template to work on the client's PC. The application works for around 200 people accessing 2000 documents with 1 template document across network. Will it not be a task to install a local printer for each and every user accessing the template? Is there a work around or something? "Jonathan West" wrote: > > "Vidhya" <Vidhya(a)discussions.microsoft.com> wrote in message > news:E9D346F1-FC64-439E-8FE8-FB62CB127E66(a)microsoft.com... > >I have the same query as Keith. I worked over the coding. But the printing > > doesnt take any effect on duplex. I work on the network over a shared > > printer. It gives the messate 'Unable to set shared printer settings'. Why > > is > > that? Isnt the same like changing the 'Duplex' value to 2/3 in the > > Printing > > preferences? > > > > thanks in advance > > You'll need a locally-installer printer driver for that code to work. > > > -- > Regards > Jonathan West > > . >
From: Vidhya on 21 Jan 2010 22:46 Hi, The printer access was changed. I modified the desiredaccess to PRINTER_ALL_ACCESS. Now there is no error. But duplex printing doesnt occur. should I change anything else? -Vidhya "Jonathan West" wrote: > > You'll need a locally-installer printer driver for that code to work. > > > -- > Regards > Jonathan West > > . >
|
Next
|
Last
Pages: 1 2 Prev: Get user input when document is created from template Next: Non-modal forms and multiple documents |