Outlook in VB.NET

F

fniles

I am using VB.NET 2005. I created a project using the Microsoft Outlook 8.0
Object Library (Object Model) in my previous machine. Now that I have a new
machine, when I try to compile that program in the new machine, it gives me
erros like "Type 'Outlook.Application' is not defined", "Type
'Outlook.NameSpace' is not defined".
I have MS Outlook in my new machine.
In the new machine when I go to "Add Reference", select the COM tab, the
only MS Outlook listed is "Microsoft Outlook 11.0 Object Library", while in
the previous machine both "Microsoft Outlook 11.0 Object Library" and
"Microsoft Outlook 8.0 Object Model".
If I select "Microsoft Outlook 11.0 Object Library", in the program when I
type in "dim ol as new", only "OutlookMail" is listed, while in the previous
machine "Outlook" and "OutlookMail" are listed.
How can I compile this program in my new machine ?

Thank you.
 
B

Brian Tillman

fniles said:
I am using VB.NET 2005. I created a project using the Microsoft
Outlook 8.0 Object Library (Object Model) in my previous machine. Now
that I have a new machine, when I try to compile that program in the
new machine, it gives me erros like "Type 'Outlook.Application' is
not defined", "Type 'Outlook.NameSpace' is not defined".
I have MS Outlook in my new machine.
In the new machine when I go to "Add Reference", select the COM tab,
the only MS Outlook listed is "Microsoft Outlook 11.0 Object
Library", while in the previous machine both "Microsoft Outlook 11.0
Object Library" and "Microsoft Outlook 8.0 Object Model".
If I select "Microsoft Outlook 11.0 Object Library", in the program
when I type in "dim ol as new", only "OutlookMail" is listed, while
in the previous machine "Outlook" and "OutlookMail" are listed.
How can I compile this program in my new machine ?

Ask in microsoft.public.outlook.program_vba
 
F

Family Tree Mike

Brian Tillman said:
Ask in microsoft.public.outlook.program_vba

But it's not a VBA question, unless I'm missing something.

I believe that you need to have the earliest version of outlook on the
development platform that you wish to support. Outlook 8.0 is Outlook '97,
so do you really need to support that?
 
K

Ken Slovak - [MVP - Outlook]

There are no .NET specific programming groups for Outlook, the group Brian
recommended is as good as any.

You need the earliest version but Outlook 2000 was the first to support COM
Addins. Managed code for Outlook versions earlier than 2003 is funky and not
really the best way to go. There is a PIA for Outlook 2002 that can be
modified to work with Outlook 2000, but not everything works correctly. If
you now have Outlook 2003 on your computer program for that unless there's
some reason you still need to support an 11 year old version of Outlook.
 
F

fniles

Both machines actually has Outlook 2003, but in the new machine I can not
see "Outlook" when I do "dim x as new ....", even though I already select
"Microsoft Outlook 11.0 Object Library"
This is the codes that I use to send email in VB.NET 2005:

Public Class OutlookMail
Public Function startOutlook(ByVal toVal As String, ByVal subjectVal As
String, ByVal bodyVal As String)
'Return a reference to the MAPI layer
Dim ol As New Outlook.Application() --> in the new machine this
gives the error "Type 'Outlook.application' is not defined
Dim ns As Outlook.NameSpace --> in the new machine this gives the
error "Type 'Outlook.NameSpace' is not defined
Dim fdMail As Outlook.MAPIFolder --> in the new machine this gives
the error "Type 'Outlook.MAPIFolder' is not defined

ns = ol.GetNamespace("MAPI")

'Logs on the user
'Profile: This is a string value that indicates what MAPI profile to
use for logging on. Leave blank if using the currently logged on user, or
set to an empty string ("") if you wish to use the default Outlook Profile.
'Password: The password for the indicated profile. Leave blank if
using the currently logged on user, or set to an empty string ("") if you
wish to use the default Outlook Profile password.
'ShowDialog: Set to True to display the Outlook Profile dialog box.
'NewSession: Set to True to start a new session. Set to False to use
the current session.
ns.Logon(, , True, True)

'create a new MailItem object
Dim newMail As Outlook.MailItem --> in the new machine this gives
the error "Type 'Outlook.MailItem' is not defined

'gets defaultfolder for my Outlook Outbox
fdMail =
ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox) --> in the new
machine this gives the error "Name 'Outlook' is not declared

'assign values to the newMail MailItem
newMail = fdMail.Items.Add(Outlook.OlItems.olMailItem) --> in the
new machine this gives the error "Name 'Outlook' is not declared
newMail.Subject = subjectVal
newMail.Body = bodyVal
newMail.To = toVal
newMail.SaveSentMessageFolder = fdMail
'adds it to the draft box
'newMail.Save()

'adds it to the outbox
newMail.Send()
End Function
 
K

Ken Slovak - [MVP - Outlook]

Then there's something wrong about your Outlook project reference, or the
Outlook PIA's aren't installed correctly, or there's something wrong with
your installation of Visual Studio.

Try removing the Outlook reference and then re-adding it, making sure you
are taking the reference from the COM tab and that the PIA is installed in
the GAC.
 
B

Brian Tillman

Family Tree Mike said:
But it's not a VBA question, unless I'm missing something.

What you're missing is that this group isn't geared for programming
questions. Since there is no .NET programming group, the vba group will, at
least, have other programmers visiting it. You MAY find a programmer here,
like Ken Slovak, but you're more likely to have your message viewed by
someone who can help if you're in a programming group. It's like being at a
convention and wanting to ask a medical question of a cardiologist. There
certainly might find that one of the attendees is a cardiologist, but your
chances are better if the convention is a physician's convention. (Although
you might run into a cardiologist in this newsgroup, too.)
 
F

Family Tree Mike

Brian Tillman said:
What you're missing is that this group isn't geared for programming
questions. Since there is no .NET programming group, the vba group will, at
least, have other programmers visiting it. You MAY find a programmer here,
like Ken Slovak, but you're more likely to have your message viewed by
someone who can help if you're in a programming group. It's like being at a
convention and wanting to ask a medical question of a cardiologist. There
certainly might find that one of the attendees is a cardiologist, but your
chances are better if the convention is a physician's convention. (Although
you might run into a cardiologist in this newsgroup, too.)

Actually, this really threw me for a loop, until I just saw that this
message also went to Microsoft.Public.Outlook. I was viewing it from
Microsoft.Public.DotNet.Languages.VB, which does have programmers (and I
suppose cardiologists from time to time).
 
K

Ken Slovak - [MVP - Outlook]

A PIA is what is used to provide an interface between a COM component and
the managed code. The GAC (global assembly cache) is where PIA's are stored.
 
K

Ken Slovak - [MVP - Outlook]

Open Windows Explorer and navigate to C:\Windows\Assembly. That's the GAC
folder. Microsoft.Office.Interop.Outlook is the Outlook PIA and Microsoft.
The Office PIA is just "office".
 
F

fniles

Thank you.
In both old and new machines, in the folder C:\Windows\Assembly, I do see
Microsoft.Office.Interop.Outlook and the version is 11.0.0.0.

In VB.NET, to add the Outlook reference, I go to the COM tab and I select
"Microsoft Outlook 11.0 Object Library", is that correct ?
After that, in the new machine I still can not see "Outlook" when I do "dim
x as new ...."

How can I fix it ?
Thank you.
 
K

Ken Slovak - [MVP - Outlook]

Aside from adding the PIA reference you have to refer to it one of two ways,
depending on how you set up your code. If you use something like this:

Imports Outlook = Microsoft.Office.Interop.Outlook

You can use statements like this:

Dim mail As Outlook.MailItem

If you don't use an Imports statement then you would declare mail like this:

Dim mail As Microsoft.Office.Interop.Outlook.MailItem
 
F

fniles

Thank you !
The following fixed my problem:
Imports Outlook = Microsoft.Office.Interop.Outlook

Thanks again for all your help !
 

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