Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I need to have numerous toggle buttons on a spread sheet. Rather than
have to replicate most of the macro code many times, I'd like to substitute a variable for an object name in the lines of code. 'First I define ToggleBut as a string, and then I assign a value: Dim ToggleBut as string ToggleBut = "ToggleButton1" 'I then test the value of the object as shown in the next line, but the test fails because my grammer is incorrect. If ToggleBut.Value = False Then 'The code works when I use: If ToggleButton1.Value = False Then Obviously there is a problem with the way I am using a string variable as an object name. What am I doing wrong? The actual code is shown below. - - - - - - - - Dim SheetNamed, ToggleBut As String Private Sub ToggleButton2_Click() SheetNamed = "2-SR" ToggleBut = "ToggleButton2" Application.Run macro:="sheet7.Std_Toggle" End Sub Sub Std_Toggle() If ToggleBut.Value = False Then ToggleBut.Caption = "Hide " & SheetNamed Sheets(SheetNamed).Visible = True Else ToggleBut.Caption = "Unhide " & SheetNamed Sheets(SheetNamed).Visible = False End If End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Runtime Error '91' Object variable or With block variable not set | Excel Discussion (Misc queries) | |||
Object Variable Not Set Error on Selection object | Excel Worksheet Functions | |||
Run-time error '91': "Object variable or With block variable not set | Excel Programming | |||
Cells.Find error Object variable or With block variable not set | Excel Programming | |||
Pivot Table - Object variable or with block variable not set? | Excel Programming |