PDA

View Full Version : Print when Command button is pushed



prabhadixit
06-13-2008, 01:13 PM
Hi,

I?m new to VBA and have a question on printing through a macro. I want to put a ?Print?Command button on my worksheet and when this button is clicked, I want the worksheet to be printed or the print dialog box to open. How do I do this? I have created the command button and hence have the Private Sub CommandButton1_Click() created. But what should I code inside this sub? Also how do I change the text on the Command button?

Thanks

grichey
06-13-2008, 01:33 PM
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

prabhadixit
06-13-2008, 01:50 PM
Thanks Gavin. Can you tell me how to access the print diolog box through code? Also how do I change the display text on the Command Button?

thanks

lucas
06-13-2008, 03:24 PM
This should show the print dialog box:
Application.Dialogs(xlDialogPrint).Show

To change the text on the command button you need to right click on any toolbar and put a check next to visual basic. When you see the visual basic toolbar select the one that says "design mode" when you hover over it. You should then be able to right click on your button and select properties. Change the caption in the properties.......many other options are also available in the properties box such as font, color, background color, etc.

prabhadixit
06-15-2008, 05:35 PM
Thank you! That works :)