Consulting

Results 1 to 4 of 4

Thread: VBA to Send Email Using NEW Outlook

  1. #1

    VBA to Send Email Using NEW Outlook

    Hello,

    I have now switched to the New Outlook, but the VBA code I use for sending emails to people appears not to work. I have been looking into this for weeks now and can't find a solution. Does anyone know how to fix this please?

    Please see my VBA code below.

    Thanks in advance. Kind regards,

    Johno

    Dim EmailAddr As String, OutApp As Object, OutMail As Object, strbody As String
    Dim WSHnet As Object
    Dim OL As Object, olAllUsers As Object, oExchUser As Object, oentry As Object, User As String
    Set WSHnet = CreateObject("WScript.Network")
    Set OL = CreateObject("outlook.application")
    Set olAllUsers = OL.Session.AddressLists.Item("All Users").AddressEntries
    User = OL.Session.CurrentUser.Name
    Set oentry = olAllUsers.Item(User)
    Set oExchUser = oentry.GetExchangeUser()
    EmailAddr = ""
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    strbody = "Hello. This is my email. " & vbNewLine & vbNewLine & _
     "Regards," & vbNewLine & vbNewLine & _
    "Me"
    With OutMail
    EmailAddr = 'myemailaddress'
    .To = EmailAddr
    .Subject = " Example Email"
    .Body = strbody
    .Send
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
    Load CloseCheck
    CloseCheck.Show
    End Sub
    Last edited by Aussiebear; 10-11-2023 at 12:54 PM. Reason: Added code tags to supplied code

  2. #2
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    337
    Location
    Please post code between CODE tags to retain indentation and readability.

    When I run my old code it still opens message in the old Outlook. Change .Send to .Display and see what you get.
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    This works here. ?????

    Option Explicit
    
    Sub emlsnd()
    Dim EmailAddr As String, OutApp As Object, OutMail As Object, strbody As String
    Dim WSHnet As Object
    Dim OL As Object, olAllUsers As Object, oExchUser As Object, oentry As Object, User As String
    Set WSHnet = CreateObject("WScript.Network")
    Set OL = CreateObject("outlook.application")
    'Set olAllUsers = OL.Session.AddressLists.Item("All Users").AddressEntries
    'User = OL.Session.CurrentUser.Name
    'Set oentry = olAllUsers.Item(User)
    'Set oExchUser = oentry.GetExchangeUser()
    'EmailAddr = ""
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    strbody = "Hello. This is my email. " & vbNewLine & vbNewLine & _
    "Regards," & vbNewLine & vbNewLine & _
    "Me"
    With OutMail
    EmailAddr = "myemailaddress"
    .To = EmailAddr
    .Subject = " Example Email"
    .Body = strbody
    '.Send
    .Display
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
    'Load CloseCheck
    'CloseCheck.Show
    End Sub

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    welcome to VBAX Johno. When posting code to this forum please wrap your code with code tags. See the first line in my signature to see how this is done.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •