VBA Print Routine

wid2001

New Member
Joined
Jan 30, 2014
Messages
28
I have a workbook with multiple sheets, some of which are hidden. Currently I have a button on a userform with this code for printing

Code:
Private Sub cmd_printfltplan_Click()
Dim Printx As String
Dim sCurrentPrinter As String


'Setting the current printer to the active printer
sCurrentPrinter = ActivePrinter


ActivePrinter = sCurrentPrinter
Printx = InputBox("How many copies would you like?")
Sheets(Array("175", "RAW", "LFR")).PrintOut Copies:=Printx 


End Sub

This works for printing the listed sheets but I would like to hide the sheets I am going to print (175, RAW, LFR) so that the user interfaces with my userform and just prints the sheets. Hiding the sheets causes my print routine to fail. I know I have to unhide during the printing process but I have not been able to write the code to make it work. Anyone have any suggestions? I have found multiple routines using screen updating on the forum but haven't been able to make anything fit what I am doing.

Thanks
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try this, it will ask for print count, then it will un-hide the sheets, print them and re-hide them... the user will be none the wiser and will never see anything happen...

There is no need to call out the printer, it should use the default printer for Excel:

Code:
Private Sub cmd_printfltplan_Click()

Dim Printx As String

Application.ScreenUpdating = False

Printx = InputBox("How many copies would you like?")
ShtsToHide = Array("175", "RAW", "LFR")

For Each ShtName In ShtsToHide
    Worksheets(ShtName).Visible = True
Next ShtName

    Sheets(Array("175", "RAW", "LFR")).PrintOut Copies:=Printx

For Each ShtName In ShtsToHide
    Worksheets(ShtName).Visible = False
Next ShtName

Application.ScreenUpdating = True

End Sub
 
Upvote 0
That worked great. I had to dim ShtsToHide and shtname as variants but once I did that it worked perfect. Thanks for the help!
 
Upvote 0
I had to dim ShtsToHide and shtname as variants
ShtsToHide should be dimmed as Worksheet and shtname as String.
If you are going to dim them as Variant then you might as well not declare any of the variables (and remove Option Explicit)
 
Last edited:
Upvote 0
Glad it worked for ya, sorry forgot to add the Dims on them for ya...
 
Upvote 0

Forum statistics

Threads
1,215,497
Messages
6,125,155
Members
449,208
Latest member
emmac

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