I'm having printing problems because I do not have the Microsoft VB Printer Dialog(PSS) aka (vbprndlg.dll) in my references-it's missing. Does anyone know where I can get it? Thanks.
Printable View
I'm having printing problems because I do not have the Microsoft VB Printer Dialog(PSS) aka (vbprndlg.dll) in my references-it's missing. Does anyone know where I can get it? Thanks.
I've never heard of that reference before, what is it? Are you sure you need it?
I just did a hard drive wide search of my machine, and I don't even have the file on my PC, but I've not had any printing issues.Quote:
Originally Posted by manofsteel00
What are you trying to print and how are you trying to print it?
Ok here's the code:
I'm getting the "User defined Type not defined" error when creating the PrinterDlg object.VB Code:
Dim printDlg As PrinterDlg Set printDlg = New PrinterDlg ' Set the starting information for the dialog box based on the current ' printer settings. printDlg.PrinterName = Printer.DeviceName printDlg.DriverName = Printer.DriverName printDlg.Port = Printer.Port ' Set the default PaperBin so that a valid value is returned even ' in the Cancel case. printDlg.PaperBin = Printer.PaperBin ' Set the flags for the PrinterDlg object using the same flags as in the ' common dialog control. The structure starts with VBPrinterConstants. printDlg.Flags = VBPrinterConstants.cdlPDNoSelection _ Or VBPrinterConstants.cdlPDNoPageNums _ Or VBPrinterConstants.cdlPDReturnDC Printer.TrackDefault = False ' When CancelError is set to True the ShowPrinterDlg will return error ' 32755. You can handle the error to know when the Cancel button was ' clicked. Enable this by uncommenting the lines prefixed with "'**". '**printDlg.CancelError = True ' Add error handling for Cancel. '**On Error GoTo Cancel If Not printDlg.ShowPrinter(Me.hWnd) Then Debug.Print "Cancel Selected" Exit Sub End If 'Turn off Error Handling for Cancel. '**On Error GoTo 0 Dim NewPrinterName As String Dim objPrinter As Printer Dim strsetting As String ' Locate the printer that the user selected in the Printers collection. NewPrinterName = UCase$(printDlg.PrinterName) If Printer.DeviceName <> NewPrinterName Then For Each objPrinter In Printers If UCase$(objPrinter.DeviceName) = NewPrinterName Then Set Printer = objPrinter End If Next End If ' Copy user input from the dialog box to the properties of the selected printer. Printer.Copies = printDlg.Copies Printer.Orientation = printDlg.Orientation Printer.ColorMode = printDlg.ColorMode Printer.Duplex = printDlg.Duplex Printer.PaperBin = printDlg.PaperBin Printer.PaperSize = printDlg.PaperSize Printer.PrintQuality = printDlg.PrintQuality ' Display the results in the immediate (Debug) window. ' NOTE: Supported values for PaperBin and Size are printer specific. Some ' common defaults are defined in the Win32 SDK in MSDN and in Visual Basic. ' Print quality is the number of dots per inch. With Printer Debug.Print .DeviceName If .Orientation = 1 Then strsetting = "Portrait. " Else strsetting = "Landscape. " End If Debug.Print "Copies = " & .Copies, "Orientation = " & _ strsetting If .ColorMode = 1 Then strsetting = "Black and White. " Else strsetting = "Color. " End If Debug.Print "ColorMode = " & strsetting If .Duplex = 1 Then strsetting = "None. " ElseIf .Duplex = 2 Then strsetting = "Horizontal/Long Edge. " ElseIf .Duplex = 3 Then strsetting = "Vertical/Short Edge. " Else strsetting = "Unknown. " End If Debug.Print "Duplex = " & strsetting Debug.Print "PaperBin = " & .PaperBin Debug.Print "PaperSize = " & .PaperSize Debug.Print "PrintQuality = " & .PrintQuality If (printDlg.Flags And VBPrinterConstants.cdlPDPrintToFile) = _ VBPrinterConstants.cdlPDPrintToFile Then Debug.Print "Print to File Selected" Else Debug.Print "Print to File Not Selected" End If Debug.Print "hDC = " & printDlg.hDC End With rtb.SelPrint printDlg.hDC Exit Sub '**Cancel: '**If Err.Number = 32755 Then '** Debug.Print "Cancel Selected" '**Else '** Debug.Print "A nonCancel Error Occured - "; Err.Number '**End If
Here's a link. It's a revised control from Microsoft that lets you use a CDC to print. It resolves issues with selecting the printer on the fly.
http://support.microsoft.com/default...322710/EN-US/?
Quote:
SUMMARY
You can use the Vbprndlg.dll file instead of the Print dialog box portion of the Visual Basic CommonDialog control. This file exposes properties and provides functionality that the CommonDialog control does not.
The CommonDialog control in Visual Basic permits the Print dialog box to be displayed, but it does not give access to many of the properties that can be set in the Print dialog box and consumed by the Printer object. Because of alignment problems with structures (that is, user-defined types) when the Win32 application programming interface (API) functions are made from Visual Basic, you cannot reliably obtain additional information by using these API calls. As a workaround, this article provides a DLL that you can use instead of the Printer portion of the CommonDialog control.
I still have not gotten that code to work. It will pop up a screen and let me select a printer, but once I click print it does nothing. I'm also been trying to tweek this code:
VB Code:
Dim printDlg As PrinterDlg Set printDlg = New PrinterDlg ' Set the starting information for the dialog box based on the current ' printer settings. printDlg.PrinterName = Printer.DeviceName printDlg.DriverName = Printer.DriverName printDlg.Port = Printer.Port ' Set the default PaperBin so that a valid value is returned even ' in the Cancel case. printDlg.PaperBin = Printer.PaperBin ' Set the flags for the PrinterDlg object using the same flags as in the ' common dialog control. The structure starts with VBPrinterConstants. printDlg.Flags = VBPrinterConstants.cdlPDNoSelection _ Or VBPrinterConstants.cdlPDNoPageNums _ Or VBPrinterConstants.cdlPDReturnDC Printer.TrackDefault = False ' When CancelError is set to True the ShowPrinterDlg will return error ' 32755. You can handle the error to know when the Cancel button was ' clicked. Enable this by uncommenting the lines prefixed with "'**". '**printDlg.CancelError = True ' Add error handling for Cancel. '**On Error GoTo Cancel If Not printDlg.ShowPrinter(Me.hWnd) Then Debug.Print "Cancel Selected" Exit Sub End If 'Turn off Error Handling for Cancel. '**On Error GoTo 0 Dim NewPrinterName As String Dim objPrinter As Printer Dim strsetting As String ' Locate the printer that the user selected in the Printers collection. NewPrinterName = UCase$(printDlg.PrinterName) If Printer.DeviceName <> NewPrinterName Then For Each objPrinter In Printers If UCase$(objPrinter.DeviceName) = NewPrinterName Then Set Printer = objPrinter End If Next End If ' Copy user input from the dialog box to the properties of the selected printer. Printer.Copies = printDlg.Copies Printer.Orientation = printDlg.Orientation Printer.ColorMode = printDlg.ColorMode Printer.Duplex = printDlg.Duplex Printer.PaperBin = printDlg.PaperBin Printer.PaperSize = printDlg.PaperSize Printer.PrintQuality = printDlg.PrintQuality ' Display the results in the immediate (Debug) window. ' NOTE: Supported values for PaperBin and Size are printer specific. Some ' common defaults are defined in the Win32 SDK in MSDN and in Visual Basic. ' Print quality is the number of dots per inch. With Printer Debug.Print .DeviceName If .Orientation = 1 Then strsetting = "Portrait. " Else strsetting = "Landscape. " End If Debug.Print "Copies = " & .Copies, "Orientation = " & _ strsetting If .ColorMode = 1 Then strsetting = "Black and White. " Else strsetting = "Color. " End If Debug.Print "ColorMode = " & strsetting If .Duplex = 1 Then strsetting = "None. " ElseIf .Duplex = 2 Then strsetting = "Horizontal/Long Edge. " ElseIf .Duplex = 3 Then strsetting = "Vertical/Short Edge. " Else strsetting = "Unknown. " End If Debug.Print "Duplex = " & strsetting Debug.Print "PaperBin = " & .PaperBin Debug.Print "PaperSize = " & .PaperSize Debug.Print "PrintQuality = " & .PrintQuality If (printDlg.Flags And VBPrinterConstants.cdlPDPrintToFile) = _ VBPrinterConstants.cdlPDPrintToFile Then Debug.Print "Print to File Selected" Else Debug.Print "Print to File Not Selected" End If Debug.Print "hDC = " & printDlg.hDC End With rtb.SelPrint printDlg.hDC Exit Sub '**Cancel: '**If Err.Number = 32755 Then '** Debug.Print "Cancel Selected" '**Else '** Debug.Print "A nonCancel Error Occured - "; Err.Number '**End If
However, this only prints if there is a textbox on the form. I have a listbox on my for and the listbox does not have a method called SelPrint(). Anyone have any suggestions?
You cannot print just a listbox. You can however print a form that it's on using
VB Code:
PrintForm Form1
in the dialog instead of printing the RTB.
You can print the contents of a listbox easily enough.Quote:
Originally Posted by dglienna
VB Code:
Dim lngIndex As Long For lngIndex = 0 To List1.ListCount - 1 Printer.Print List1.List(lngIndex); Next Printer.EndDoc
I meant the actual listbox, not the items IN the listbox :)
Hack rocks!
You have to use Hacks method since if you have items in your listbox that are wider then the displayable width of the listbox, they would be chopped off and not printed.. ;)
Thanks guys, it works
One quick question though: How can I change the font size? When it prints out it prints a little smaller than I would like for it to. I already tried changing the font size on the listbox property itself but it was not reflected when it was printed.
Change the .Fontsize property of the Printer object.
VB Code:
Printer.ForeColor = vbRed Printer.Font = "Times New Roman" Printer.FontSize = 16 Printer.FontItalic = True Printer.FontUnderline = True Printer.Print "This is in Red" Printer.Print Printer.Font = "Arial" Printer.FontSize = 12 Printer.FontBold = True Printer.Forecolor = vbGreen Printer.Print "This is Green Arial font" Printer.EndDoc
Fantastic code dude. Thanks for you help.