Outlook Accounts

I guess I don't understand where to apply your code to mine? Which lines...
 
Not sure I follow you, I took your code from post # 10 and added the code to loop through all accounts and send using one of the two you mention. If both are available on one specific computer it will use the one that comes first in the loop.

If you only have two computers then you can use a simple If statement to select which account to use:
Code:
If Environ$("computername")="Computer1" Then   
    .SentOnBehalfOfName = "info1@testing.com"
Else
    .SentOnBehalfOfName = "info2@testing.com"
End If

Cheers,
 
I tried your code... Seems to work but every other time I click the button, I get this error?

1640193267465.png


Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Dim oAccount As Outlook.Account
Set appOutLook = CreateObject("Outlook.Application")

For Each oAccount In appOutLook.Session.Accounts
If oAccount = "results@testing.com" Or oAccount = "results1@testing.com" Then
Set MailOutLook = CreateItem(olMailItem)
MailOutLook.SendUsingAccount = oAccount
End If
Next
 
Please post the entire code that you have for the button (replace the real emails with your testing ones).
 
Set MailOutLook = CreateItem(olMailItem) is where it turns yellow. I think it might have something to do with Outlook not being opened first?

Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Dim oAccount As Outlook.Account
Set appOutLook = CreateObject("Outlook.Application")

For Each oAccount In appOutLook.Session.Accounts
If oAccount = "results@testing.com" Or oAccount = "results1@testing.com" Then
Set MailOutLook = CreateItem(olMailItem)
MailOutLook.SendUsingAccount = oAccount
End If
Next
 
Please try this fully qualified line:
Set MailOutLook = appOutLook.CreateItem(olMailItem) Set MailOutLook.SendUsingAccount = oAccount

Cheers,
 

Users who are viewing this thread

Back
Top Bottom