VBA to choose Outlook Profile (1 Viewer)

vinz4ever

New member
Local time
Today, 14:13
Joined
May 1, 2012
Messages
7
Hi,

I've got VBA to open Outlook and create an email but as i have 3 different Outlook profiles i need code that automatically selects the profile.

On a button, once that is pressed it opens an email with pre written text then sends it but then closes Outlook and reopens outlook, but this time i need it to pick a different profile in which another message is created and sent.

What can i do to make it pick a particular profile then close Outlook and then open Outlook and pick a different profile?

Thanks
 

darbid

Registered User.
Local time
Today, 15:13
Joined
Jun 26, 2008
Messages
1,428
I know this is an old thread, but I just wanted to clean it up and answer it for next time.

The answer is to us the LOGON method of the MAPI object in Outlook.
Here is a link to the full explanation.
http://msdn.microsoft.com/en-us/library/office/ff861594.aspx

Below is an example of logging on to the default profile with NO dialog.
Code:
Dim olApp As Outlook.Application
Dim oNS As Outlook.Namespace
Set olApp = GetObject(, "Outlook.Application")
Set oNS = olApp.GetNamespace("MAPI")
oNS.Logon "", "", False, True

If you change that "False" to a true then you should get a dialog and you can then choose your profile.
 

smiler44

Registered User.
Local time
Today, 14:13
Joined
Jul 15, 2008
Messages
641
if the code does not open outlook express what would the tweek be to make it open outlook express?

thanks smiler44
 

Isskint

Slowly Developing
Local time
Today, 14:13
Joined
Apr 25, 2012
Messages
1,302
an alternative way would be to use the /profile profilename switch if the profile is known. Not sure if this will work with the code from darbid, but it will work with the SHELL() function. EG to open outlook at the vinz4ever profile use outlook.exe/ profile "vinz4ever" so

Code:
x=SHELL("\\path to outlook\outlook.exe/ profile "vinz4ever")
 

Users who are viewing this thread

Top Bottom