LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Userform to Select what worksheets to print

Paul,

I'll leave the print settings to you, as I'm sure you'll be able to work out getting the range to one page that is centered. However, assuming that your userform has two comboboxes (ComboBox1 and ComboBox2) as well as a CommandButton, the following code should do what you need (place on the UserForm code module).

Hope this helps,

Ben

Private Sub CommandButton1_Click()
Dim lCbo(1 To 2) As Long

If Len(Me.ComboBox1.Text) < 1 Then
MsgBox "Please choose a start sheet."
Me.ComboBox1.SetFocus
Exit Sub
ElseIf Len(Me.ComboBox2.Text) < 1 Then
MsgBox "Please choose an end sheet."
Me.ComboBox2.SetFocus
Exit Sub
End If

lCbo(1) = Sheets(Me.ComboBox1.Text).Index
lCbo(2) = Sheets(Me.ComboBox2.Text).Index

If lCbo(1) lCbo(2) Then
Call printsheets(lCbo(2), lCbo(1))
Else
Call printsheets(lCbo(1), lCbo(2))
End If


End Sub

Private Sub UserForm_Initialize()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
Me.ComboBox1.AddItem ws.Name
Me.ComboBox2.AddItem ws.Name
Next
End Sub
Sub printsheets(lFirst As Long, lLast As Long)
Dim l As Long

For l = lFirst To lLast
On Error Resume Next
Sheets(l).Range("A1:AQ104").PrintOut PrintToFile:=True
If Err.Number = 1004 Then
Err.Clear
Else
MsgBox "Unhandled error: " & vbCr & vbCr & _
"Error number: " & Err.Number & vbCr & _
Err.Description
Err.Clear
End If
Next l

Unload Me

End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to print a workbook but worksheets have diff print areas Angela Steele Excel Discussion (Misc queries) 1 January 17th 08 07:39 PM
How do I print a workbook in but only print selected worksheets? Karl S. Excel Discussion (Misc queries) 1 August 31st 06 12:34 AM
Create a print macro that would automatically select print area? wastedwings Excel Worksheet Functions 7 August 22nd 05 10:36 PM
How do I select multiple worksheets for print preview? steve Excel Programming 3 May 10th 05 07:01 PM
Userform, multipage, select a tab Jos Vens[_2_] Excel Programming 2 February 28th 05 04:11 PM


All times are GMT +1. The time now is 07:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"