#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Print Macro


I want to print an array of sheets that are selected by check boxes so
the pages print in order. Here is my code, but I get an error in the
array, can someone help with this? Thanks!!

Private Sub Cmd_Print_Click()

Dim A As String
Dim B As String
Dim C As String

If CheckBox1.Value = True Then
A = "Sheet1"
End If
If CheckBox2.Value = True Then
B = "Sheet2"
End If
If CheckBox3.Value = True Then
C = "Sheet3"
End If

F = A & B & C

Sheets(Array(F)).Select
ActiveWindow.SelectedSheets.PrintOut

End Sub


--
LaraBee
------------------------------------------------------------------------
LaraBee's Profile: http://www.excelforum.com/member.php...o&userid=30275
View this thread: http://www.excelforum.com/showthread...hreadid=499436

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Print Macro

Are these checkboxes on a worksheet (from the Control Toolbox toolbar) or are
they on a UserForm (designed in the VBE)?

If they're on a worksheet:

Option Explicit
Private Sub Cmd_Print_Click()
Dim shtCtr As Long
Dim myArr() As String
Dim selCtr As Long

selCtr = -1
For shtCtr = 1 To 3
If Me.OLEObjects("checkbox" & shtCtr).Object.Value = True Then
selCtr = selCtr + 1
ReDim Preserve myArr(0 To selCtr)
myArr(selCtr) = "Sheet" & shtCtr
End If
Next shtCtr

If selCtr = -1 Then
MsgBox "None selected"
Else
Worksheets(myArr).PrintOut preview:=True
End If

End Sub

If they're on a UserForm, change this line:
If Me.OLEObjects("checkbox" & shtCtr).Object.Value = True Then
to
If Me.Controls("checkbox" & shtCtr).Value = True Then


LaraBee wrote:

I want to print an array of sheets that are selected by check boxes so
the pages print in order. Here is my code, but I get an error in the
array, can someone help with this? Thanks!!

Private Sub Cmd_Print_Click()

Dim A As String
Dim B As String
Dim C As String

If CheckBox1.Value = True Then
A = "Sheet1"
End If
If CheckBox2.Value = True Then
B = "Sheet2"
End If
If CheckBox3.Value = True Then
C = "Sheet3"
End If

F = A & B & C

Sheets(Array(F)).Select
ActiveWindow.SelectedSheets.PrintOut

End Sub

--
LaraBee
------------------------------------------------------------------------
LaraBee's Profile: http://www.excelforum.com/member.php...o&userid=30275
View this thread: http://www.excelforum.com/showthread...hreadid=499436


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Print Macro


Thanks for your response. It is on a worksheet, not a form. The only
problem is that the real sheets and checkboxes are not named 1,2,3,etc.
I just posted that way for simplicity. How would I set this up if the
sheets and checkboxes just have random text names?


--
LaraBee
------------------------------------------------------------------------
LaraBee's Profile: http://www.excelforum.com/member.php...o&userid=30275
View this thread: http://www.excelforum.com/showthread...hreadid=499436

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Print Macro

Don't use random names for the checkboxes. Use checkbox1, checkbox2, ...

And put the name of the worksheet in the caption of each checkbox. Then the
macro can pick up the name from that caption.

Option Explicit
Private Sub Cmd_Print_Click()
Dim shtCtr As Long
Dim myArr() As String
Dim selCtr As Long
Dim OLEObj As OLEObject

selCtr = -1
For shtCtr = 1 To 3
Set OLEObj = Me.OLEObjects("checkbox" & shtCtr)
If OLEObj.Object.Value = True Then
selCtr = selCtr + 1
ReDim Preserve myArr(0 To selCtr)
myArr(selCtr) = OLEObj.Object.Caption
End If
Next shtCtr

If selCtr = -1 Then
MsgBox "None selected"
Else
Worksheets(myArr).PrintOut preview:=True
End If

End Sub

LaraBee wrote:

Thanks for your response. It is on a worksheet, not a form. The only
problem is that the real sheets and checkboxes are not named 1,2,3,etc.
I just posted that way for simplicity. How would I set this up if the
sheets and checkboxes just have random text names?

--
LaraBee
------------------------------------------------------------------------
LaraBee's Profile: http://www.excelforum.com/member.php...o&userid=30275
View this thread: http://www.excelforum.com/showthread...hreadid=499436


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Print Macro


PERFECT!!!!

Thank you so much!


--
LaraBee
------------------------------------------------------------------------
LaraBee's Profile: http://www.excelforum.com/member.php...o&userid=30275
View this thread: http://www.excelforum.com/showthread...hreadid=499436



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Print Macro

Woohoo!!!

Glad it worked for you.

LaraBee wrote:

PERFECT!!!!

Thank you so much!

--
LaraBee
------------------------------------------------------------------------
LaraBee's Profile: http://www.excelforum.com/member.php...o&userid=30275
View this thread: http://www.excelforum.com/showthread...hreadid=499436


--

Dave Peterson
Reply
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
Pivot Table macro to set print area and print details of drill down data Steve Haskins Excel Discussion (Misc queries) 2 December 28th 05 04:59 PM
Macro to open print window and set to print entire workbook retseort Excel Discussion (Misc queries) 1 October 27th 05 11:00 PM
Create a print macro that would automatically select print area? wastedwings Excel Worksheet Functions 7 August 22nd 05 10:36 PM
Why does macro speed slow after Excel Print or Print Preview? Larry A[_3_] Excel Programming 6 May 16th 05 11:22 AM
Need Help w/ Print Macro to Print All Visible Sheets (including Charts) in a Workbook will Excel Programming 3 September 23rd 04 08:05 PM


All times are GMT +1. The time now is 09:08 PM.

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

About Us

"It's about Microsoft Excel"