Outlook COM ad-in - problem with adressing Commandbars

  • Thread starter Thread starter Bjørn Eliasen
  • Start date Start date
B

Bjørn Eliasen

Hi,

When trying to convert a macro to a COM object for Outlook XP I stumpled
across the following problem

In

IDTExtensibility2_OnConnection

I perform a

Set olApp = Application
Set olSession = olApp.GetNamespace("MAPI")

and then

Set menu = olApp.ActiveExplorer.CommandBars.ActiveMenuBar

Every time this fires a:

'Commandbars' of object '_Explorer' failure.

It believe it is not a declaration problem, and gets the error whatever
method of Commandbars I try.
Any hints will be much appriciated.

Regards, Bjørn
 
Thank you for your proposal. Unfortunately this had no effect. In
"IDTExtensibility2_OnConnection"

I still wrote
Set olApp = Application
Set olSession = olApp.GetNamespace("MAPI")
And then added
set myExpl = olApp.ActiveExplorer

In myExpl_Activate()

Set menu = myExpl.CommandBars.ActiveMenuBar

fails with the same error as before.
Am I missing something?

Regards Bjørn
 
Did you look at the ItemsCB sample that Dmitry pointed you to? It
shows how to create and access toolbars and also shows the best
practices for Outlook addins.
 
Hello,

you should have an
Private WithEvents m_objExpl As Outlook.Explorer
in your AddIn

create / activate your commandbar in the event

Private Sub m_objExpl_Activate()


--
regards,
Helmut Obertanner
DATALOG Software AG
http://www.datalog.de
[obertanner at datalog dot de]
 
Hi,

Thanks.

After ia while I tried to compile the code, and now it is working ok! I
guess that loading a COM ad-in which is intended to load at startup by
starting the debugger and then invoking it by the internal COM-add in list
might not work.

I did have a look at the ItemCB sample but failed to find the
IDTExtensibility2 code?

Regards, Bjørn


Helmut Obertanner said:
Hello,

you should have an
Private WithEvents m_objExpl As Outlook.Explorer
in your AddIn

create / activate your commandbar in the event

Private Sub m_objExpl_Activate()


--
regards,
Helmut Obertanner
DATALOG Software AG
http://www.datalog.de
[obertanner at datalog dot de]


Bjørn Eliasen said:
Thank you for your proposal. Unfortunately this had no effect. In
"IDTExtensibility2_OnConnection"

I still wrote
Set olApp = Application
Set olSession = olApp.GetNamespace("MAPI")
And then added
set myExpl = olApp.ActiveExplorer

In myExpl_Activate()

Set menu = myExpl.CommandBars.ActiveMenuBar

fails with the same error as before.
Am I missing something?

Regards Bjørn
 
Instead of
myExpl.CommandBars.ActiveMenuBar
try to use
myExpl.CommandBars.Item("Menu Bar")

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Back
Top