Userform commands to print and convert to PDF

mcooer0913

New Member
Joined
Feb 16, 2009
Messages
22
I am trying to make a userform command button (cmdPrintClientData) print a worksheet ("Client Statistics"). I would like for the user to be taken directly from the userform to a print dialogue box where he/she can select a printer (as if he/she had selected "Print" while viewing the "Client Statistics" worksheet).

Also, I would like to place a button next to it (cmdConvertClientData) that allows the user to convert the same data to a PDF.

Any suggestions?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Assuming a pdf converter is installed (in my case pdfFactory) this would print the sheet to pdf, via a print preview.

Code:
activeworksheet.printout preview:=true, activeprinter:="pdfFactory"

You could select your activeprinter, maybe with a list box to give you the choice of printer. But this is machine specific. And it is going to be cumbersome if you don't know what printers are installed and whether your users have a different selection. You'd need to leave them to fill the list.
 
Upvote 0
try this
Code:
Sub Print_Reports()
bResponse = Application.Dialogs(xlDialogPrinterSetup).Show
If TypeName(response) = "Boolean" Then Exit Sub

End Sub
Code:
Sub CreatePDF()
   Dim curPrinter As String
   curPrinter = Application.ActivePrinter
   Application.ActivePrinter = "PDF-XChange 2.5 on Ne01:"
   ActiveWindow.SelectedSheets.PrintOut
   Application.ActivePrinter = curPrinter
End Sub
 
Upvote 0
Code:
Sub CreatePDF()
   Dim curPrinter As String
   curPrinter = Application.ActivePrinter
   Application.ActivePrinter = "PDF-XChange 2.5 on Ne01:"
   ActiveWindow.SelectedSheets.PrintOut
   Application.ActivePrinter = curPrinter
End Sub

I'm still learning some VB fundamentals, and am not quite sure how to implement this code. Would it look like this (cmdConvertClientStatistics is the button I'm using for this):
Code:
Private Sub cmdConvertClientStatistics_Click()
Sub CreatePDF()
   Dim curPrinter As String
   curPrinter = Application.ActivePrinter
   Application.ActivePrinter = "PDF-XChange 2.5 on Ne01:"
   ActiveWindow.SelectedSheets.PrintOut
   Application.ActivePrinter = curPrinter
End Sub
End Sub
 
Upvote 0
in the command button tyr call CreatePDF like this, this will go in the command button code window.
Code:
Private Sub cmdConvertClientStatistics()
call CreatePDF
end sub

this will call that macro to run. or you can do this
this is the same command button code window.
Code:
Private Sub cmdConvertClientStatistics()
 Dim curPrinter As String
   curPrinter = Application.ActivePrinter
   Application.ActivePrinter = "PDF-XChange 2.5 on Ne01:"
   ActiveWindow.SelectedSheets.PrintOut
   Application.ActivePrinter = curPrinter
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top