B
Bryan Loeper
I'm making a toolbar dynamically to hide columns of a workbook. If I
use Columns(i).Hidden = True|False, it works. If I use it in the
below sub (set to the .OnAction of the toolbar button), it doesn't
work correctly, although the sub continues to run past it. The .Tag
nonsense was because it was getting fired twice per button click, so I
added that to keep track of the button's clicked state more
accurately. Any ideas on why my column won't hide?
Sub ButtonToggle()
Dim ctlPressed As CommandBarButton
Dim i As Long
Set ctlPressed = Application.CommandBars.ActionControl
With ctlPressed
i = .index + 1
If .Tag = "0" Then
If .State = msoButtonDown Then
.State = msoButtonUp
Else
.State = msoButtonDown
End If
Columns(i).Hidden = .State
.Tag = "1"
Else
.Tag = "0"
End If
End With
End Sub
use Columns(i).Hidden = True|False, it works. If I use it in the
below sub (set to the .OnAction of the toolbar button), it doesn't
work correctly, although the sub continues to run past it. The .Tag
nonsense was because it was getting fired twice per button click, so I
added that to keep track of the button's clicked state more
accurately. Any ideas on why my column won't hide?
Sub ButtonToggle()
Dim ctlPressed As CommandBarButton
Dim i As Long
Set ctlPressed = Application.CommandBars.ActionControl
With ctlPressed
i = .index + 1
If .Tag = "0" Then
If .State = msoButtonDown Then
.State = msoButtonUp
Else
.State = msoButtonDown
End If
Columns(i).Hidden = .State
.Tag = "1"
Else
.Tag = "0"
End If
End With
End Sub