Outlook COM ad-in - problem with adressing Commandbars

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
 
B

Bjørn Eliasen

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
 
K

Ken Slovak - [MVP - Outlook]

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.
 
H

Helmut Obertanner

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]
 
B

Bjørn Eliasen

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
 
D

Dmitry Streblechenko

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
 

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