Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Form Control Text box

I am trying to use a form control text box to hide tabs in a worksheet
and I cant seem to get it to work any suggestions.
Sub CheckBox_Click()
If ActiveSheet.CheckBoxes("Check Box 1").Value = 1 Then
Sheets("Sheet2").Visible = False
Else
Sheets("Sheet2").Visible = True
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Form Control Text box

TextBox or CheckBox? Be sure your control name is correct:

"Check Box 1" and "CheckBox1" are two different names

CheckBoxes is not a collection, but OLEObjects is.

Or ActiveSheet.CheckBox1 = True will also work.

"newguy" wrote in message
...
I am trying to use a form control text box to hide tabs in a worksheet
and I cant seem to get it to work any suggestions.
Sub CheckBox_Click()
If ActiveSheet.CheckBoxes("Check Box 1").Value = 1 Then
Sheets("Sheet2").Visible = False
Else
Sheets("Sheet2").Visible = True
End If
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Form Control Text box

It works for me, but I had to rename it CheckBox1_Click.

It can also be reduced to

Sub CheckBox1_Click()
Sheets("Sheet2").Visible = ActiveSheet.CheckBoxes("Check Box 1").Value =
1
End Sub


--
__________________________________
HTH

Bob

"newguy" wrote in message
...
I am trying to use a form control text box to hide tabs in a worksheet
and I cant seem to get it to work any suggestions.
Sub CheckBox_Click()
If ActiveSheet.CheckBoxes("Check Box 1").Value = 1 Then
Sheets("Sheet2").Visible = False
Else
Sheets("Sheet2").Visible = True
End If
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Form Control Text box

It is a check box and the I right click on the check box the name is
Check Box 1.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Form Control Text box

The Checkboxes collection are for checkboxes from the Forms toolbar.

JLGWhiz wrote:

TextBox or CheckBox? Be sure your control name is correct:

"Check Box 1" and "CheckBox1" are two different names

CheckBoxes is not a collection, but OLEObjects is.

Or ActiveSheet.CheckBox1 = True will also work.

"newguy" wrote in message
...
I am trying to use a form control text box to hide tabs in a worksheet
and I cant seem to get it to work any suggestions.
Sub CheckBox_Click()
If ActiveSheet.CheckBoxes("Check Box 1").Value = 1 Then
Sheets("Sheet2").Visible = False
Else
Sheets("Sheet2").Visible = True
End If
End Sub


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Form Control Text box

Make sure your procedure is in a General module and assign your macro to the
checkbox.

Then you could modify your code so that it doesn't rely on the name of the
checkbox.

Option Explicit
Sub CheckBox_Click()
dim CBX as checkbox
set cbx = activesheet.checkboxes(application.caller)

if cbx.value = xlon then
worksheets("sheet2").visible = false
else
worksheets("Sheet2").visible = true
end if
end sub



newguy wrote:

I am trying to use a form control text box to hide tabs in a worksheet
and I cant seem to get it to work any suggestions.
Sub CheckBox_Click()
If ActiveSheet.CheckBoxes("Check Box 1").Value = 1 Then
Sheets("Sheet2").Visible = False
Else
Sheets("Sheet2").Visible = True
End If
End Sub


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Form Control Text box

Hi newguy

Try the below code, its working for me.

Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
Worksheets("Sheet2").Visible = True
Else
Worksheets("Sheet2").Visible = False
End If
End Sub


"newguy" wrote:

I am trying to use a form control text box to hide tabs in a worksheet
and I cant seem to get it to work any suggestions.
Sub CheckBox_Click()
If ActiveSheet.CheckBoxes("Check Box 1").Value = 1 Then
Sheets("Sheet2").Visible = False
Else
Sheets("Sheet2").Visible = True
End If
End Sub

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Form Control Text box

Actually, the code seems to work for me. Are you getting any error messages
with it?


"newguy" wrote in message
...
I am trying to use a form control text box to hide tabs in a worksheet
and I cant seem to get it to work any suggestions.
Sub CheckBox_Click()
If ActiveSheet.CheckBoxes("Check Box 1").Value = 1 Then
Sheets("Sheet2").Visible = False
Else
Sheets("Sheet2").Visible = True
End If
End Sub



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Form Control Text box

The error message I get is "Cannot run the macro 'Test.xlsm!
Sheet1.CheckBox_Click' The Macro may not be available in the workbook
or all macros may be disabled."

I checked the Trust center and allowed Macros to Run and it is in the
General Module.
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Form Control Text box

You have to enable macros for macros to run.

And it looks like the current macro assigned to this checkbox is not in a
general module (or at least the pointer to the macro doesn't think so).

Rightclick on the checkbox (not really a textbox, right???) and reassign the
correct macro.



newguy wrote:

The error message I get is "Cannot run the macro 'Test.xlsm!
Sheet1.CheckBox_Click' The Macro may not be available in the workbook
or all macros may be disabled."

I checked the Trust center and allowed Macros to Run and it is in the
General Module.


--

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
2007 Form Control/ActiveX Control font difference Nikko963 Excel Discussion (Misc queries) 0 April 15th 09 04:21 PM
Can text in check box created with form control be word wrapped? Breck Excel Programming 1 February 15th 09 01:42 AM
problems adding Rich Text Box control to a VBA form? Mad Scientist Jr Excel Programming 1 July 18th 07 03:17 AM
Printing the contents of a text control on a user form Chaplain Doug Excel Programming 3 May 24th 06 08:32 PM
Tool Tip Text for Form control/ Active-X control Freddie[_2_] Excel Programming 0 October 19th 04 04:14 AM


All times are GMT +1. The time now is 09:37 AM.

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"