VBA to change Outlook 2010 Account (1 Viewer)

GaryPanic

Smoke me a Kipper,Skipper
Local time
Yesterday, 23:23
Joined
Nov 8, 2005
Messages
3,296
Hi Guys
I have a minor issue and I am simplify the problem as much as I can
OK - I need to use a different profile (?) account when I am doing busines/emails in the EU
I already have a trigger that I can use (EU yes/no) tick box

what i am after is somehow if EU (true/ticked etc) then use this outlook profile /account

If me.eu=-1 then
something to set to right profile/account ( I may have to do a dlookup here )

*then the mail bit
Dim mi As Outlook.MailItem
Dim ID As String
Dim sentAfter As Date
Dim LetterName As String
blah blah blah....
my coding goes a bit bonkers here
so I have not included this bit

*but it should send from this profile with the email inbox/sent box that applies


else use the default one

all good fun
 

GaryPanic

Smoke me a Kipper,Skipper
Local time
Yesterday, 23:23
Joined
Nov 8, 2005
Messages
3,296
missed the bit that might help
How do I set the Email to use EU setting and then if not eu default
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:23
Joined
Sep 21, 2011
Messages
14,048
I have used The SendUsing property in the past.?
Code:
            .SendUsingAccount = objOutlook.Session.Accounts.Item(intAccount)

intAccount is set prior to this. (It depends on the order of your accounts)

Use this (modified ) to either return the account by number dynamically
Code:
Public Function ListEMailAccounts(AcctToUSe As String) As Integer
    Dim outApp As Object
    Dim i As Integer
    Dim AccNo As Integer
    Dim emailToSendTo As String
    
    Set outApp = CreateObject("Outlook.Application")
    'emailToSendTo = "xxxxx@gmail.com"                    'put required email address
    AccNo = 1
    'if smtp address=email we want to send to, acc no we are looking for is identified
    For i = 1 To outApp.Session.Accounts.Count
        'Uncomment the Debug.Print command to see all email addresses that belongs to you
'Debug.Print "Acc name: " & OutApp.Session.Accounts.Item(i) & " Acc number: " & i & " , email: " & OutApp.Session.Accounts.Item(i).SmtpAddress
        'If OutApp.Session.Accounts.Item(i).SmtpAddress = emailToSendTo Then
        If outApp.Session.Accounts.Item(i).DisplayName = AcctToUSe Then

            AccNo = i
            Exit For
        End If
    Next i
    ListEMailAccounts = AccNo
    Set outApp = Nothing
End Function

HTH
 

GaryPanic

Smoke me a Kipper,Skipper
Local time
Yesterday, 23:23
Joined
Nov 8, 2005
Messages
3,296
Ooh... I will digest this one - not sure i understand some of this - but I don't need to uderstand it before I try it - i can work it backwards
 

Users who are viewing this thread

Top Bottom