VB 6 COM Add-in for Outlook 2007

  • Thread starter Thread starter goran
  • Start date Start date
G

goran

Hi All,

I have a working Outlook 2003 COM add-in written in VB 6.0 based on Ken's
ItemsCB template with Inspector wrapper class. It adds custom toolbar with
few buttons and dropdown on the Inspector window. It works in Outlook 2007,
but it is located under 'Add-ins' tab. What should I change so it will show
up on the 'Message' tab instead, and use existing code in button_click event.
Also what would be the easiest way to convert this to VSTO add-in for
Outlook 2007 so I don't have to change much.

Thanks,

Goran
 
What you have to do is check for versioning of the running Outlook and if
the major value is "12" you know it's Outlook 2007. Then you fork your code
to handle the ribbon in that case instead of creating the CommandBars UI you
would use for Outlook 2003 and earlier ("11" or less).

The easiest way to do that in VB6 code is to download Dennis Wallentin's
(XL-Dennis) XLIRibbonExtensibility tlb from his Web site and reference that
everywhere you want to use Ribbon extensibility. That lets you handle the
callbacks from the ribbon and to supply your custom XML for your Ribbon UI.

An alternative is to put the Office 2007 MSO file on your dev system and
reference that for the ribbon stuff, the CLSID's are compatible so your code
will still run under earlier versions of Office.

There's no conversion from VB6 to .NET code, except manually. You can start
a VSTO Outlook 2007 project and cut and paste your VB6 code in and then hand
translate it into VB.NET code. You have to take into account changes such as
changing all of your VB6 Long variables into VB.NET Int's and so on. That's
what I did to get my own templates and library code into VB.NET from VB6,
and I did the same translating the VB6 into C# for my C# templates.

The problem with VSTO is that if you develop for Outlook 2007 that's the
only version it will run on. If you develop for Outlook 2003 it will run on
Outlook 2007 but with no ribbon support. Since the shim is pre-compiled for
VSTO that means that Dennis's method doesn't work well with VSTO in
deployment, although the code works. For multi-version support in managed
code I use shared addins and a hack of the custom shims provided for the
Outlook team's sample addins that I modified to support Outlook 2003 with
shimmed ribbon support.
 
Thanks Ken for your prompt reply. I used Dennis's tlb to fork the code and
create CommandBar if it is version 11 or use GetCustomUI method in connect
module in the case of office 12.
I have my xml file for the ribbon. When I run it it shows up nicely, but how
can I hook the onAction to run the code that I already have for Button_click.
When specifying onAction callback it tries to find it in connect designer
module, and my buttons and associated events are declared my Inspector
wrapper class.

Thanks,

Goran
 
That's where the sneaky part comes in :)

In cases like that I put a public property in my Inspector wrapper class
called Ribbon that is set to the Ribbon object in my Connect class (or you
can make the Ribbon object in Connect global). I also put in the wrapper
class a public Sub that I usually call RibbonClicker().

I also have a public Inspector property in the wrapper class that returns
the Inspector for that class.

In Outlook 2007 you can directly compare control.Context from the ribbon
callback to the Inspector property in each existing wrapper class instance
using equality:

If (control.Context = wrapper(i).Inspector) Then

So I always can get the correct Inspector wrapper class.

I then call into the wrapper class's RibbonClicker() procedure, passing
along the ribbon control.ID as an argument to RibbonClicker().

In RibbonClicker() I compare the id (ribbon control tag) to the tags for all
the available ribbon controls and from that I know which control was clicked
and which button event handler it corresponds to. I then set up a dummy null
CommandBarButton and a dummy boolean Cancel variable and pass those to the
appropriate button click event handler, which then executes the code for
that event handler.

In cases where I need to pass other information to the eventual procedure to
handle the clicks I have both the button event handler and the ribbon
clicker procedure call the same child procedure to execute the click code.
 
Thanks a lot as always Ken.

This thing worked, and I am able to route callbacks to my specific Wrapper
code. But now I am confused. I used to have dropdown control in inspector
wrapper that I declared as:
Private WithEvents CBInspectorDropdown As Office.CommandBarComboBox,

and then I pull the items from DB and populated this dropdown when Inspector
opened. I also had _Change event for the dropdown where I would put the code
to do something based on user selection. Now, I defined dropdown in xml. How
can i reference that dropdown in my code in vb 6 and load with items in the
runtime, get selected item etc.

thanks,

Goran
 
The ribbon combo is populated by XML when the control is initialized,
therefore it's not so great for dynamically populated lists. About the only
way I've found to do that is to actually create the ribbon XML on the fly
when GetCustomUI fires.

For dynamically populated controls I usually prefer to use the dynamicMenu
control, which has a getContent callback that's used to provide the XML for
the control. You still have to create that XML on the fly but you don't have
to create the entire ribbon XML on the fly. Of course the dynamicMenu
control doesn't have that textbox associated with it.

For combo's you get an onChange callback.

You might find the articles starting at
http://msdn2.microsoft.com/en-us/library/aa338202.aspx to be of interest.
The code samples are in C# and VB.NET, but they're simple and readable.
 
Thanks Ken. And where should I check this if
(control.context=wrapper(i).inspector?

In the connection module or in inspector wrapper class?
 
I can create xml dynamically. But how can I reference combobox in the code
once it is populated? For example, when I click on the button next to
combobox I want to get the currently selected index and selected text. Do I
refer to it by id that I specified in the xml?

Thanks,

Goran
 
Unfortunately that's not exposed.

Dennis's tlb doesn't expose some ribbon-related methods in the Office 12
library such as ExecuteMso(idMSO) or GetEnabledMso(idMSO), but there isn't a
method for reading either of those combo properties.

You have to track the state of any property you want to evaluate yourself.
When the combo's onChange() callback fires you would update your property
variables. The second of those articles I referenced has a complete list of
all combo callbacks.
 
And if I want to use Office 12 library and I have Outlook 2007 installed, are
there ways to get currently selected dropdown text and index like it used in
Office 11?
 
There isn't a method for reading either of those combo properties, no matter
what reference or library you use. The ribbon designers didn't think we'd
need things like that.
 
Thanks.

Ken Slovak - said:
There isn't a method for reading either of those combo properties, no matter
what reference or library you use. The ribbon designers didn't think we'd
need things like that.
 
Hi Ken,

Could you tell me where I can get hold of the XLIRibbonExtensibility tlb? -
I can't find it anywhere :(

Many thanks,

Rob Holmes.
podia.
 
Back
Top