none
VBA- How do I send an email to a user? RRS feed

  • Question

  • I'm a newcomer to VBA. I want to use VBA to send an email to a user. Please help me, thanks in advance.
    Wednesday, October 31, 2018 2:01 PM

All replies

  • Hi sara1984,

    You could send an email via VBA use the below code:

    Sub CommandButton1_Click()
    Dim olApp As Outlook.Application
    Dim olMail As Outlook.MailItem
    Dim olAccount As Outlook.Account
    Set olApp = New Outlook.Application
    Set olMail = olApp.CreateItem(olMailItem)
    With olMail
    .To = "user email address"
    .Subject = "test"
    .Body = "test“
    .Send
    End With

    End Sub

    Regards,

    Alina

    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Thursday, November 1, 2018 1:59 AM
  • Thanks for your asking. Did you resolve your issue ? If the post helps you, you can mark it as answer and close the post. Thank you for understanding. If you have any question, or update, please feel free to let us know. I wish you a happy life!

    Regards,

    Alina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Wednesday, November 7, 2018 2:43 AM