Outlook New Session VB Problem

  • Thread starter Thread starter Neil Penn
  • Start date Start date
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
 
Please see my response to your post in the
microsoft.public.outlook.program_vba group.
 
Back
Top