I tested a quickie Sub that creates a button on a toolbar and toggles
its .State property. No errors and no problems.
See if this helps you at all:
Sub testbutton()
Dim objCommandBar As Office.CommandBar
Dim myCmdBarBtn As Office.CommandBarButton
Dim myOlApp As Outlook.Application
Set myOlApp = GetObject(, "Outlook.Application")
Set objCommandBar =
myOlApp.ActiveInspector.CommandBars.Add("Messages", , , True)
objCommandBar.Visible = True
objCommandBar.Enabled = True
Set myCmdBarBtn = objCommandBar.Controls.Add(msoControlButton)
myCmdBarBtn.Caption = "test button"
myCmdBarBtn.Enabled = True
myCmdBarBtn.Visible = True
Set myCmdBarBtn = Nothing
Set myCmdBarBtn = objCommandBar.Controls(1)
If myCmdBarBtn.State = msoButtonUp Then
myCmdBarBtn.State = msoButtonDown
End If
End Sub
DaveH said:
Thanks, Ken... I understand why this doesn't work now... But, I'm
having trouble figuring out how to get a CommandBarButton object that
is updateable. As you said, the help guide seems a little skimpy, but
here's where I "think" I have to go, based on the Outlook Visual Basic
Reference Help:
"CommandBars Property
Returns a CommandBars collection object that represents all the
menus and toolbars in the Explorer or Inspector.
expression.CommandBars
expression Required. An expression that returns an Explorer or Inspector object."
Okay... but, the rest of that help page seems to get me in a loop
(Explorer and Inspector are hyperlinks that keep referring back to
themselves...). When I use the regular VB reference and look at
Office Objects I see there is a CommandBars collection that has a
CommandBarControls child collection, which in turn has three child
objects (one of which is CommandBarButton). However, from there it
appears to say I should use the Controls(1) to get the first button
per the following:
"Using the CommandBarButton Object
Use Controls(index), where index is the index number of the control,
to return a CommandBarButton object. (The Type property of the control
must be msoControlButton.)"
I set watches on all my objects and they appear to be the correct
types right up thru the end, but I still get the failure in the last
line of this code snippet: