Custom Form and firing Revise Contents button

C

Christopher Slowik

Hi,

We have a custom form that creates a post in a public folder. In Outlook
2007, when a user opens a posting in this folder, they cannot edit the body
of the post until they click the "Revise Contents" button. I'd like to
execute this button on the Item_Open event so they do not have to click this
manually. I have the code below, but nothing seems to happen:

Dim objInsp
Dim colCB
Dim objCBB
On Error Resume Next
Set objInsp = Item.GetInspector
Set colCB = objInsp.CommandBars
Set objCBB = colCB.FindControl(, 3273)
If Not objCBB Is Nothing Then
'MsgBox objCBB.Caption
objCBB.Execute
End If
Set objCBB = Nothing
Set colCB = Nothing
Set objInsp = Nothing

Thanks for any help

-Chris
 
K

Ken Slovak - [MVP - Outlook]

In the Outlook 2007 Ribbon that ribbon control has an idMso of
"ReviseContents". Use Inspector.CommandBars.ExecuteMso("ReviseContents") on
open to do what you want.
 
C

Christopher Slowik

Ken, thanks for the information. I still cannot get this to fire. As a
test, I created a standard Post Item in a test folder. Placed the code below
in the Item_Open event but it never seems to fire.

MsgBox "Here we are"
Dim objInsp
On Error Resume Next
Set objInsp = Item.GetInspector
objInsp.CommandBars.ExecuteMso("ReviseContents")
Set objInsp = Nothing

Thanks
 
K

Ken Slovak - [MVP - Outlook]

Are you saying the MsgBox doesn't fire or something else?

In some cases things are only weak object references at the time the
Item_Open() event fires in form code.

In an addin I'd get those things in the first Inspector.Activate() event
handler, but that can't be done in form code. I also sometimes use a timer
to wait out the completion of an event, but again that can't be done in form
code.

I'd comment out the On Error line and see what line fires an error. In
addition, I'd also set up a CommandBars object and instantiate that as
objInsp.CommandBars, then if that was valid I'd call ExecuteMso() on that
object.
 
C

Christopher Slowik

Hi Ken,

No the MsgBox fires. Here is the changed code.

Dim objInsp
Dim objCB
'On Error Resume Next
Set objInsp = Item.GetInspector
Set objCB = objInsp.CommandBars
If Not objCB Is Nothing Then
MsgBox "Here we are with objCB"
objCB.ExecuteMso("ReviseContents")
End If

Set objInsp = Nothing
Set objCB = Nothing

the line "objCB.ExecuteMso("ReviseContents")" throws the following error:

Invalid procedure call or argument
Line No:11
 
K

Ken Slovak - [MVP - Outlook]

Just for fun try it with this line instead:

objCB.ExecuteMso "ReviseContents"

Of course this will only run without error on Outlook 2007...
 
K

Ken Slovak - [MVP - Outlook]

It looks like the added methods in the CommandBars collection aren't
available at all in Item_Open, either in form code or in Outlook VBA. They
are available when the first Inspector.Activate() event fires.

I hit an error both in the form code and Outlook VBA when I called
CommandBars.ExecuteMso() in Item_Open. I didn't in the first
Inspector.Activate() on that Inspector, however that's not an event you can
sink in form code.

The other gotcha related to this is that calling
ExecuteMso("ReviseContents") will open a new Inspector and close the
existing one (same item, but now in edit mode). So any Activate() code would
have to account for that since both NewInspector() and Inspector.Activate()
will fire again when that new Inspector is opened.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top