Thread: Print Macro
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
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