Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Need to print a workbook but worksheets have diff print areas | Excel Discussion (Misc queries) | |||
How do I print a workbook in but only print selected worksheets? | Excel Discussion (Misc queries) | |||
Create a print macro that would automatically select print area? | Excel Worksheet Functions | |||
How do I select multiple worksheets for print preview? | Excel Programming | |||
Userform, multipage, select a tab | Excel Programming |