none
Can I use a “Microsoft Word Macro” to send email?

    Question

  •  Can I use a “Microsoft Word Macro” to send email?

    How to do that?

    This is discussion is open to suggestions.

    Many thanks for your replying.

    Wednesday, August 15, 2007 3:47 AM

Answers

  • Hi

     

    The simple answer is yes.  The following is a very, very simple example and requires you to set up a reference to Microsoft Outlook (In VBA Tools/References)

     

    Code Snippet

    Dim ola             As Outlook.Application
    Dim maiMessage      As Outlook.MailItem


    Sub Sendmail()

    Set ola = New Outlook.Application
    Set maiMessage = ola.CreateItem(olMailItem)
    With maiMessage
        .Subject = "Subject"
        .Recipients.Add Name:="Name or address"
        .Attachments.Add Source:=FullFileName
        .Send
    End With

    End Sub

     

     

    You can add multiple recipients and control whether they are To, CC or BCC recipients.  You can also add multiple attachments.  If you want to get clever you can also have different formats of the body of the email.  As always plenty of areas to explore and the help becomes visible as soon as you set up the reference.

     

    Regards

     

    Peter Mo.

    Wednesday, August 15, 2007 5:48 PM

All replies

  • Hi

     

    The simple answer is yes.  The following is a very, very simple example and requires you to set up a reference to Microsoft Outlook (In VBA Tools/References)

     

    Code Snippet

    Dim ola             As Outlook.Application
    Dim maiMessage      As Outlook.MailItem


    Sub Sendmail()

    Set ola = New Outlook.Application
    Set maiMessage = ola.CreateItem(olMailItem)
    With maiMessage
        .Subject = "Subject"
        .Recipients.Add Name:="Name or address"
        .Attachments.Add Source:=FullFileName
        .Send
    End With

    End Sub

     

     

    You can add multiple recipients and control whether they are To, CC or BCC recipients.  You can also add multiple attachments.  If you want to get clever you can also have different formats of the body of the email.  As always plenty of areas to explore and the help becomes visible as soon as you set up the reference.

     

    Regards

     

    Peter Mo.

    Wednesday, August 15, 2007 5:48 PM
  • Thank you very much.

    It is very helpful for me.

    Thursday, August 16, 2007 1:09 AM
  •  

    I recommand you to use Excel though. It is very easy to pull fields from spread sheets and generate a HTML page for the email content. Excel is the easiest to work with because data lines up in a simple grid. Word is much trickier.
    Thursday, August 16, 2007 11:15 PM