Outlook Accounts (1 Viewer)

kitty77

Registered User.
Local time
Today, 04:53
Joined
May 27, 2019
Messages
693
I guess I don't understand where to apply your code to mine? Which lines...
 

bastanu

AWF VIP
Local time
Today, 01:53
Joined
Apr 13, 2010
Messages
1,401
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,
 

kitty77

Registered User.
Local time
Today, 04:53
Joined
May 27, 2019
Messages
693
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
 

bastanu

AWF VIP
Local time
Today, 01:53
Joined
Apr 13, 2010
Messages
1,401
Please post the entire code that you have for the button (replace the real emails with your testing ones).
 

kitty77

Registered User.
Local time
Today, 04:53
Joined
May 27, 2019
Messages
693
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
 

bastanu

AWF VIP
Local time
Today, 01:53
Joined
Apr 13, 2010
Messages
1,401
Please try this fully qualified line:

Set MailOutLook = appOutLook.CreateItem(olMailItem)
Set MailOutLook.SendUsingAccount = oAccount


Cheers,
 

Users who are viewing this thread

Top Bottom