Problem starting Outllook programmatically

J

jon morgan

Hi All

Can anyone see what's wrong with the following code snippet:

Private Function GetOutlookFolder(ByVal foldername As String) As
Outlook.MAPIFolder

Try
oApp = CreateObject("Outlook.Application")
oNS = oApp.GetNamespace("mapi")
oNS.Logon("Outlook", "", False, False)
Catch doh As System.Exception
MessageBox.Show(doh.Message)
Return Nothing
End Try
Return oNS.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderContacts).Folders.Item(foldername)

End Function

The error is thrown at oNS.Logon - "Outlook server unavailable".

If I use oApp=GetObject("",OutlookApplication") the code works fine as long
as Outlook is already booted, but I want to boot it programmatically.

Thanks for your help.

Jon
 
S

Sue Mosher [MVP-Outlook]

Your code assumes that the user has a mail profile named Outlook, which may not be a valid assumption.

Some anti-virus programs also block access to CreateObject("Outlook.Application").

FYI, there is a newsgroup specifically for general Outlook programming issues "down the hall" at microsoft.public.outlook.program_vba or, via web interface, at http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public.outlook.program_vba

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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