Printing the selected sheets

  • Thread starter Thread starter suee
  • Start date Start date
S

suee

HI, im writing code for a form, when the user clicks on OK, I want th
selected sheets that were checked to be printed. Was hoping you coul
help with the code to do this.


Private Sub OKButton_Click()
'insert code here.....................

For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
With Sheets(ListBox1.List(i))
.PageSetup.PrintGridlines = cbGridlines
If obLandscape Then .PageSetup.Orientation
xlLandscape
If obPortrait Then .PageSetup.Orientation = xlPortrait
' .PrintOut
End With
End If
Next i
Unload Me
End Su
 
Hi suee

This may help - you'll need to add your own specific code, etc, but this
selects the relevant sheets for printing from a list box.

Private Sub CommandButton1_Click()
Dim b As Boolean, i As Integer, ws As Worksheet
Set ws = ActiveSheet
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Sheets(ListBox1.List(i)).Select Not b
b = True
End If
Next i
Unload Me
'use PrintOut below if preferred
ActiveWindow.SelectedSheets.PrintPreview
ws.Select
End Sub


--
XL2002
Regards

William

(e-mail address removed)

| HI, im writing code for a form, when the user clicks on OK, I want the
| selected sheets that were checked to be printed. Was hoping you could
| help with the code to do this.
|
|
| Private Sub OKButton_Click()
| 'insert code here.....................
|
| For i = 0 To ListBox1.ListCount - 1
| If ListBox1.Selected(i) Then
| With Sheets(ListBox1.List(i))
| PageSetup.PrintGridlines = cbGridlines
| If obLandscape Then .PageSetup.Orientation =
| xlLandscape
| If obPortrait Then .PageSetup.Orientation = xlPortrait
| ' .PrintOut
| End With
| End If
| Next i
| Unload Me
| End Sub
|
|
| ---
| Message posted
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top