VB.NET & Various Versions Of Outlook

W

wizzbangca

Hi everyone. Having problems with a utility I am writing for work.
The previous IT Director thoughtfully allowed 3 (2000, xp, 2003)
versions of outlook to be installed rather than 1. Now I need the
utility to work for all 3 versions. A previous post suggested
creating objects to detect the version of outlook, which I tried with
success. But, that's as far as I can get. No one out there shows how
to go beyond version detection to actually creating, deleting and
modifying outlook contacts, emails, and appointments. I tried creating
the extra outlook objects I need (shown bellow). So far, VB doesn't
show any errors during programming. When ran, I get an activex error:
"Cannot create Axtivex Component".

Code:
'open outlook application
Private objOutlook As Object = CreateObject("Outlook.Application")

'store outlook session
Private objNS As Object = CreateObject("Outlook.NameSpace")
'outlook folder variable
Private objFolder As Object = CreateObject("Outlook.MAPIFolder")
'outlook items variable
Private objItems As Object = CreateObject("Outlook.Items")
'outlook contact variable
Private objContact As Object = CreateObject("Outlook.ContactItem")


Private objNS As Object = CreateObject("Outlook.NameSpace") =
objOutlook.Session
doesn't create the activex component. Keep in mind, the utility works
great if I reference a specific version interop assembly. I have been
searching for the past few days without success. Has anyone else had
any success?

Thank you.
 
J

Jay B. Harlow [MVP - Outlook]

wizzbangca,
I would recommend upgrading every one to Outlook 2003, which would allow
creating a VSTO 2.0 addin for Outlook. VSTO 2.0 greatly simplifies create
Outlook add-ins in .NET!

If upgrading is not an option, then the "easiest" way is to write your
add-in to the lowest common denominator. Write the add-in to Outlook 2000,
reference Outlook 2000 type library, compile & develop against that.
Alternatively don't reference a type library & use late binding (Object
variables).

| Private objOutlook As Object = CreateObject("Outlook.Application")
Should work as Outlook.Application is a creatable object.


| 'store outlook session
| Private objNS As Object = CreateObject("Outlook.NameSpace")
Will fail as Outlook.Namespace is NOT a creatable object, you use
objOutlook.GetNamespace to get the namespace object.

| Private objOutlook As Object = CreateObject("Outlook.Application")
| Private objNS As Object = objOutlook.GetNamespace("MAPI")


Normally what I do when using Late binding & Outlook (VBScript for example)
is to write a macro in the VBIDE in Outlook (Alt+F11 when the Outlook
Explorer window is open) for intellisense. Then change all the strongly
typed variables to Object. You could probably adopt a similar method for
late binding in VB.NET...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Hi everyone. Having problems with a utility I am writing for work.
| The previous IT Director thoughtfully allowed 3 (2000, xp, 2003)
| versions of outlook to be installed rather than 1. Now I need the
| utility to work for all 3 versions. A previous post suggested
| creating objects to detect the version of outlook, which I tried with
| success. But, that's as far as I can get. No one out there shows how
| to go beyond version detection to actually creating, deleting and
| modifying outlook contacts, emails, and appointments. I tried creating
| the extra outlook objects I need (shown bellow). So far, VB doesn't
| show any errors during programming. When ran, I get an activex error:
| "Cannot create Axtivex Component".
|
| Code:
| 'open outlook application
| Private objOutlook As Object = CreateObject("Outlook.Application")
|
| 'store outlook session
| Private objNS As Object = CreateObject("Outlook.NameSpace")
| 'outlook folder variable
| Private objFolder As Object = CreateObject("Outlook.MAPIFolder")
| 'outlook items variable
| Private objItems As Object = CreateObject("Outlook.Items")
| 'outlook contact variable
| Private objContact As Object = CreateObject("Outlook.ContactItem")
|
|
| Private objNS As Object = CreateObject("Outlook.NameSpace") =
| objOutlook.Session
| doesn't create the activex component. Keep in mind, the utility works
| great if I reference a specific version interop assembly. I have been
| searching for the past few days without success. Has anyone else had
| any success?
|
| Thank you.
|
 
J

Jay B. Harlow [MVP - Outlook]

wizzbangca,
Did you try passing the "MAPI" parameter as I showed:

| Private objOutlook As Object = CreateObject("Outlook.Application")
| Private objNS As Object = objOutlook.GetNamespace("MAPI")


--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| objOutlook.GetNamespace
| Doesn't work - "Parameter not optional" error.
|
 

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