Home All Groups Group Topic Archive Search About

VB.NET & Various Versions Of Outlook

Author
29 Dec 2005 2:29 AM
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.

Author
3 Jan 2006 4:20 PM
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


Show quoteHide quote
"wizzbangca" <wizzban***@yahoo.com> wrote in message
news:1135823366.958783.281170@g14g2000cwa.googlegroups.com...
| 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.
|
Author
12 Jan 2006 11:36 PM
wizzbangca
objOutlook.GetNamespace
Doesn't work - "Parameter not optional" error.
Author
13 Jan 2006 3:20 PM
Jay B. Harlow [MVP - Outlook]
wizzbangca,
Did you try passing the "MAPI" parameter as I showed:

Show quoteHide quote
| 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


Show quoteHide quote
"wizzbangca" <wizzban***@yahoo.com> wrote in message
news:1137108989.605905.116940@g14g2000cwa.googlegroups.com...
| objOutlook.GetNamespace
| Doesn't work - "Parameter not optional" error.
|