Looks like Outlook.
I am not sure why it is doing this, but it certainly does do it. say I have Inbox as my View, and Messages is the Current View, and it is #3 (third) in the menu list:
Code:
Dim hideDeleted As CommandBarButton
Set hideDeleted = ActiveExplorer _
.CommandBars("Current View").Controls.Item(3)
msgbox hideDeleted.State & vbTab & hideDeleted.Caption
will display:
-1 Messages
msoButtonDown is indeed -1.
Say I change it to Last Seven Days = Item(5). But I run the code on Item(3) still. The display is:
0 Messages
msoButtonUp is indeed 0.
HOWEVER, as you have discovered, you can not explicitly set the State via code. WHY? I have no idea, maybe because menu items are not, technically buttons?
HOWEVER (#2): you can in fact make the State at least Down (the current view) with another method, Execute.
Code:
ActiveExplorer.CommandBars("Current View") _
.Controls.Item(2).Execute
will make the second item the CurrentView (ie. State = msoButtonDown).
The weird thing is that .Execute seems to destroy the object.
Code:
Dim hideDeleted As CommandBarButton
Set hideDeleted = ActiveExplorer _
.CommandBars("Current View").Controls.Item(2)
Msgbox hideDeleted.State & vbTab & hideDeleted.Caption
hideDeleted.Execute
Msgbox hideDeleted.State & vbTab & hideDeleted.Caption
Say item(2) is NOT selected, and you get messages on its State.
First message: 0 yaddaYadda (whatever)
.Execute
Second message.....fails "Object required"
yet .Execute
does work. If you query .State again, it will be -1. Execute only makes it True (-1), it will not make it msoButtonUp.
Search me. I do not know why.
faq219-2884
Gerry
My paintings and sculpture