Outlook New Session VB Problem

N

Neil Penn

Outlook 2000

I want to be able to logon to Outlook using a specified profile name and
perform various actions such as send mail.

My problem is that the code below only works if Outlook is not already open.
If Outlook is open then although the code runs with no error, I am actually
logged on as the existing Outlook session and not the session I logon
through my code as. Indeed, the user has to logoff with File/Exit and Log
off, and not just close Outlook for the code to work as expected.

Is there any way I can logon as another profile if Outlook is already open?

Note - I believe from some simple tests that this is possible with MAPI, but
as I already have a lot of code written to run against the Outlook object
model I would ideally like to get this running in Outlook.

Dim o As Outlook.Application
Dim m As Outlook.MailItem

Set o = New Outlook.Application
o.Session.Logon "sms", "", False, True
MsgBox o.Session.CurrentUser
Set m = o.CreateItem(olMailItem)
m.To = "(e-mail address removed)"
m.Subject = "test"
m.Send
Set m = Nothing

Set o = Nothing
 
K

Ken Slovak - [MVP - Outlook]

No can do. Outlook can only use and logon to one profile at a time.
You can use CDO 1.21 or Extended MAPI to logon to different profiles
but then you'd have to continue with the CDO or MAPI code to perform
your process.
 

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