Outlook 2003 Add-in In Outlook 2007 Inspector Commandbar btn vanis

C

cycloptic

Greetings,

I have a custom add-in for Outlook 2000/2003 created in VB6 that has been
working for a number of years in Outlook 2003. The add-in creates a command
bar button for any email inspectors that initiates some custom processing
when clicked.

Now with Outlook 2007, the add-in is recognized and the first inspector of a
new Outlook 2007 instance has the button in an generic add-in tab and the
processing executed by this button works. However, any subsequent inspectors
no longer has the add-in tab in its ribbon or the button.

I've seen several references to this behavior in some Google searches but
have yet to come across an explanation of what is going on.

Is there a bug with Outlook 2007 causing this behavior? Is there something I
need to change to make the add-in compatible?

Thanks in advance for any insights!

cycloptic
 
K

Ken Slovak - [MVP - Outlook]

I haven't seen that here, although most of my own addins have been updated
to use the ribbon if Outlook 2007 is detected running, otherwise they use
the CommandBars interface.

How are you adding your UI and where? Are you handling multiple open
Inspectors with Inspector wrappers?
 
C

cycloptic

Hi Ken,

Thanks so much for replying to this.

The add-in does implement inspector wrappers to handle multiple inspectors.
The CommandBar UI is being added in response to the Inspectors_NewInspector
event of the Inspectors object and is removed in response to the Close event
of the Inspector object.

The code that is creating the CommandBar is as follows:

Private Sub objInspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
' Initialize an inspector wrapper and add it to the collection
Add Inspector
End Sub


Public Sub Add(AnyInspector As Outlook.Inspector)

Dim objInspWrapper As New clsInspWrapper
With objInspWrapper
Set .MyInspector = AnyInspector
.Key = nID ' "auto incrementing" collection index key
.Caption = AnyInspector.Caption
Set .Parent = Me
If AnyInspector.CurrentItem.Class = olMail Then
Set .MailItem = AnyInspector.CurrentItem
Call .AddOutlookToolbar
End If
End With

colInspWrapper.Add objInspWrapper, CStr(nID)
nID = nID + 1

End Sub

' Relevant constants
Public Const IPMessageTitle = "IPSave"
Public Const BTN_CAPTION = "IP Save"
Const IPOUT_Caption = "IP Outlook Save"
Const TLBR_OUTLOOK = "IP Save Outlook Toolbar"
Const BTN_OUTLOOK = BTN_CAPTION & " Outlook"


'following is a member of inspector wrapper class
Public Sub AddOutlookToolbar()

Dim oCommandBars As Office.CommandBars
Dim oStandardBar As Office.CommandBar
Dim oitem As Object

On Error GoTo ErrAddButton

Set oCommandBars = mobjInsp.CommandBars
If Not oCommandBars Is Nothing Then
Set oStandardBar = oCommandBars.Item(TLBR_OUTLOOK)

If oStandardBar Is Nothing Then
' Add Toolbar
Set oStandardBar = oCommandBars.Add(TLBR_OUTLOOK, , , True)
Else
'If Toolbar is Created Make sure the Button is pointing to the
correct one
If btnOutlook Is Nothing Then
Set btnOutlook = oStandardBar.Controls.Item(BTN_CAPTION)
End If
End If

If btnOutlook Is Nothing Then
For Each oitem In oStandardBar.Controls
oitem.Delete
Next
' Add Button
Set btnOutlook = oStandardBar.Controls.Add(msoControlButton, , ,
, True)
oStandardBar.Visible = False
End If

If oStandardBar.Controls.Count = 0 Then
Set btnOutlook = Nothing
Set btnOutlook = oStandardBar.Controls.Add(msoControlButton, , ,
, True)
oStandardBar.Visible = False
End If

With oStandardBar
.Position = msoBarTop
.Left = oCommandBars.Item("Standard").Left +
oCommandBars.Item("Standard").Width
.RowIndex = oCommandBars.Item("Standard").RowIndex
.Visible = True
End With

With btnOutlook
.Caption = BTN_CAPTION
.ToolTipText = BTN_OUTLOOK
.Tag = BTN_OUTLOOK & mnID
.Style = msoButtonIconAndCaption
.FaceId = 271
If Len(.OnAction) = 0 Then
.OnAction = "!<IPSaveOutlook.Connect>"
End If
.Visible = True
End With
Set oStandardBar = Nothing
End If
Set oCommandBars = Nothing

Exit Sub
ErrAddButton:

' Can't Find Save Toolbar
If Err.Number = 5 Then
Resume Next
Else
Call IPError("AddOutlookToolbar")
End If

End Sub

-----------------------------------------------------
The code that removes the CommandBar is as follows:

Private Sub mobjInsp_Close()
Call RemoveOutlookToolbar
Call Parent.Remove(mnID)
End Sub

Private Sub RemoveOutlookToolbar()

Dim oCommandBars As Office.CommandBars
Dim oStandardBar As Office.CommandBar

On Error GoTo ErrRemoveOutlookButton

Set oCommandBars = mobjInsp.CommandBars

If oCommandBars.Count > 0 Then
For Each oStandardBar In oCommandBars
If oStandardBar.Name = TLBR_OUTLOOK Then
oStandardBar.Delete
Exit For
End If
Next
End If

Set oStandardBar = Nothing
Set oCommandBars = Nothing

Exit Sub

ErrRemoveOutlookButton:

If Err.Number = 5 Then
Resume Next
Else
Exit Sub
End If

End Sub

Thanks again for taking a look at this. If the above is too much code, let
me know and I try to repost what you deem relevant.

cycloptic
 
K

Ken Slovak - [MVP - Outlook]

I'd strongly recommend moving your AddOutlookToolbar() call to the first
Inspector.Activate() event handler. The Outlook 2007 NewInspector() event
provides only a weak object reference to the Inspector and
Inspector.CurrentItem object suitable mostly for getting Class and
MessageClass from the CurrentItem.

As an example, if you test for Inspector.IsWordMail() in NewInspector() you
get false and WordEditor is null there. Those properties only return the
correct values starting at the first Inspector.Activate() event.

Now why it would work on the initial Inspector and not on subsequent ones I
don't have an answer for, but let's see how things play out if you do change
that AddOutlookToolbar() call to the first Inspector.Activate() event.
 
C

cycloptic

Thanks.

I will try using the Inspector.Activate event as suggested and see what
happens.

cycloptic

Ken Slovak - said:
I'd strongly recommend moving your AddOutlookToolbar() call to the first
Inspector.Activate() event handler. The Outlook 2007 NewInspector() event
provides only a weak object reference to the Inspector and
Inspector.CurrentItem object suitable mostly for getting Class and
MessageClass from the CurrentItem.

As an example, if you test for Inspector.IsWordMail() in NewInspector() you
get false and WordEditor is null there. Those properties only return the
correct values starting at the first Inspector.Activate() event.

Now why it would work on the initial Inspector and not on subsequent ones I
don't have an answer for, but let's see how things play out if you do change
that AddOutlookToolbar() call to the first Inspector.Activate() event.
[snip...]
 
C

cycloptic

Hi Ken,

I took your suggestion and moved the toolbar call to the
Inspector.Activate() event handler, and it looks like that did the trick. And
it still works for Office 2003 as well.

Thanks very much for taking a look at this code and for your suggestion. You
just saved my hair from being pulled out!

cycloptic
 
K

Ken Slovak - [MVP - Outlook]

Although it's vital for Outlook 2007, creating the UI only in the initial
Activate() has been a best practice for a long time. It's really necessary
for WordMail. I'm glad it worked out for you.
 
C

cycloptic

Thanks,

This add-in has been around since Outlook 2000. Though I'm not the original
developer, I've been supporting it for this time. Somehow though, I missed
hearing the suggestion of using the Activate event for UI creation as a best
practice. I'll be sure to remember that going forward.

On a semi related note, I've started playing around with a VSTO C# Outlook
2003 add-in project in Visual Studio 2008 to get my feet wet a little for a
possible update to this add-in. I am not finding an Activate event for the
provided Inspector object. Where is it hidden?

cycloptic
 
K

Ken Slovak - [MVP - Outlook]

In managed code you use different handling of events in many cases than you
would in VB6.

Inspector does expose Activate(), but it conflicts with the Activate method,
so if you use that you'll get compiler warnings.

As an example for Inspector.Activate(), you could use
InspectorEvents_Event_Activate or InspectorEvents_10_Event_Activate of the
InspectorClass in C#.

In VB.NET you'd use InspectorEvents.Activate or InspectorEvents_10.Activate.
 

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