For some reason at work, my Excel Account email and my Outlook Account emails are slightly different.
My Excel email uses myworkID@***.com and I return that using Environ$("username") and then I set the variable :
My_Email = Environ$("username") & "@***.com"
However my Outlook Account email is myFirstName.LastName@****.com
If I tried sending myself an email addressing it to my Excel Account email, it would work, but when I run this code, it doesn't work( and I found out it's because I need to use the FirstName.LastName@***.com variable from outlook. )
So How would I return my outlook account Email and set it as a variable in Excel?
Thanks
My Excel email uses myworkID@***.com and I return that using Environ$("username") and then I set the variable :
My_Email = Environ$("username") & "@***.com"
However my Outlook Account email is myFirstName.LastName@****.com
If I tried sending myself an email addressing it to my Excel Account email, it would work, but when I run this code, it doesn't work( and I found out it's because I need to use the FirstName.LastName@***.com variable from outlook. )
So How would I return my outlook account Email and set it as a variable in Excel?
Thanks
VBA Code:
Sub Open_Most_Recent_Email()
Dim OlApp As Object
Dim OlMail As Object
Dim OlItems As Object
Dim OlFolder As Object
Dim i As Long
If Err <> 429 Then
Set OlApp = CreateObject("Outlook.Application")
Else
Set OlApp = GetObject(, "Outlook.Application")
End If
Set OlFolder = OlApp.GetNamespace("MAPI").Folders(Environ$("username") & "@***.com").Folders("abc")
Set OlItems = OlFolder.Items
i = OlItems.Count
OlFolder.Items(i).Display
Set OlFolder = Nothing
Set OlItems = Nothing
Set OlMail = Nothing
Set OlApp = Nothing
End Sub