Office COM Add-in using C#

C

Cedric

Hi,

When I try to use the example of KB Article ID 302901,
I get a problem with commandbars on line:
oStandardBar = oCommandBars["Standard"]

The debugers says: Error: the Object (oCommandbars)
doesn't have an indexer.

I can't find any info on MSDN.

Can anyone help?
Thanks,
Cedric
 
G

Guest

Correction:
- it works with reflection:
oCommandBars= (CommandBars)oActiveExplorer.GetType
().InvokeMember
("CommandBars",BindingFlags.GetProperty,null,oActiveExplor
er,null);
- it doesn't work the normal way:
oCommandBars = oOutlook.ActiveExplorer().CommandBars;
 
P

Peter Huang

Hi Cedric,

You may need to add reference to the Outlook Com Object.
"Microsoft Outlook 11.0 Object Library"

1. Right click on the Reference in the solution explorer and select Add
reference
2. In the "Add reference" dialog select COM tab
3. Browse to "Microsoft Outlook 11.0 Object Library" and select it to add
to the reference and click ok to close the dialog

I changed the code sinipper from the KB as follows.

try
{
Outlook.Application oOutlook=(Outlook.Application)applicationObject;
oCommandBars =(CommandBars)oOutlook.ActiveExplorer().CommandBars;
//oCommandBars = (CommandBars)applicationObject.GetType().InvokeMember
//("CommandBars", BindingFlags.GetProperty , null,
applicationObject ,null);
}
catch(Exception)
{
// Outlook has the CommandBars collection on the Explorer object.
object oActiveExplorer;
oActiveExplorer=
applicationObject.GetType().InvokeMember("ActiveExplorer",BindingFlags.GetPr
operty,null,applicationObject,null);
oCommandBars=
(CommandBars)oActiveExplorer.GetType().InvokeMember("CommandBars",BindingFla
gs.GetProperty,null,oActiveExplorer,null);
}


If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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