drom
Well-known Member
- Joined
- Mar 20, 2005
- Messages
- 543
- Office Version
- 2021
- 2019
- 2016
- 2013
- 2011
- 2010
- 2007
hi and Thanks in advance!
I have the following code:
I have 2 different Accounts in my OutLook
Debug.Pring OutApp.Session.Accounts.Count is giving me 1 despite I have 2 accounts
What am I missing ?
I have the following code:
VBA Code:
Function Fx_xToGetOutLookAccount02() As Byte
On Error Resume Next: Application.ScreenUpdating = False
Dim OutApp As Object: Set OutApp = GetObject(, "Outlook.Application")
If Err.Number = 429 Then Set OutApp = CreateObject("Outlook.application")
Dim xEmailAccounts As Long: xEmailAccounts = OutApp.Session.Accounts.Count
If xEmailAccounts = 0 Then
MsgBox "Err" & Err, Err.Description
Exit Function
End If
Dim rFrom As Range: Set rFrom = Range("eFrom1") ' Range("rMail")
Dim wFrom As String: wFrom = LCase(rFrom)
Dim wEmail As String
Dim X As Long
For X = 1 To xEmailAccounts
wEmail = "": wEmail = LCase(OutApp.Session.Accounts.Item(X))
If wFrom = wEmail Then
Fx_xToGetOutLookAccount02 = X: Exit Function
End If
Next X
If Fx_xToGetOutLookAccount02 = 0 Then
Fx_xToGetOutLookAccount02 = 1: wEmail = LCase(OutApp.Session.Accounts.Item(1))
rFrom = wEmail
MsgBox wFrom & Chr(10) & Chr(10) & "Does not exist in your Outlook" & Chr(10) & Chr(10) & _
"I will use: " & wEmail
End If
End Function
I have 2 different Accounts in my OutLook
- 1 of them is MyMail01@outlook.com (Just 4 this eg)
- the other one is MyMail01@gmail.com (Just 4 this eg)
Debug.Pring OutApp.Session.Accounts.Count is giving me 1 despite I have 2 accounts
- When I put as rFrom = "MyMail01@outlook.com" My Macro works Fine
- When I put as rFrom = "MyMail01@gmail.com" Does not work
- My Macro takes MyMail01@outlook.com
What am I missing ?