OutApp.Session.Accounts.Count does not count the gmail account

drom

Well-known Member
Joined
Mar 20, 2005
Messages
543
Office Version
  1. 2021
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
hi and Thanks in advance!
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
My Problem
Debug.Pring OutApp.Session.Accounts.Count is giving me 1 despite I have 2 accounts


What am I missing ?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Sorry just a timing problem
Once I have Closed OutLook and reopened takes the desired Account mail but still opening the 1st account
Not the desired when using

With OutMail
.Display
end with
 
Upvote 0
Solution
Sorry again a timing problem
Closed and reopened and Works OK
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top