Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Sending Email using VBA in Word

Sending Email using VBA in Word

Scheduled Pinned Locked Moved Visual Basic
algorithmshelpquestionlearning
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Harold_Wishes
    wrote on last edited by
    #1

    Hello I would like to know if there is a programmatic way to send an email message to someone from VBA in Word 2003? After searching a bunch of online references, I know there is an OUTLOOK object reference available that can be added to an existing project and that you can create an instance of the Outlook application but I do not know where to go from here. Every Outlook programming book I've peeked thru only addresses things you can do in Outlook itself, not things involving other office applications. If I can invoke this Outlook task from Word, I will be much further ahead with my project. Everything else I have in my program works fine. Any help welcome. Thanks! :)

    A 1 Reply Last reply
    0
    • H Harold_Wishes

      Hello I would like to know if there is a programmatic way to send an email message to someone from VBA in Word 2003? After searching a bunch of online references, I know there is an OUTLOOK object reference available that can be added to an existing project and that you can create an instance of the Outlook application but I do not know where to go from here. Every Outlook programming book I've peeked thru only addresses things you can do in Outlook itself, not things involving other office applications. If I can invoke this Outlook task from Word, I will be much further ahead with my project. Everything else I have in my program works fine. Any help welcome. Thanks! :)

      A Offline
      A Offline
      Anoop Brijmohun
      wrote on last edited by
      #2

      here you go.... Sub Email() Set objEmail = CreateObject("CDO.Message") objEmail.From = "" objEmail.To = "" objEmail.Subject = "TEST" objEmail.Textbody = "THIS IS A TEST EMAIL" objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "192.168.0.1" objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objEmail.Configuration.Fields.Update objEmail.Send MsgBox ("done") End Sub

      H 1 Reply Last reply
      0
      • A Anoop Brijmohun

        here you go.... Sub Email() Set objEmail = CreateObject("CDO.Message") objEmail.From = "" objEmail.To = "" objEmail.Subject = "TEST" objEmail.Textbody = "THIS IS A TEST EMAIL" objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "192.168.0.1" objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objEmail.Configuration.Fields.Update objEmail.Send MsgBox ("done") End Sub

        H Offline
        H Offline
        Harold_Wishes
        wrote on last edited by
        #3

        Hello, First, thanks for providing me this script. I ran it and everything seems to work fine until I run into the last line of code:

        objEmail.Send

        I get the following runtime error message:

        Run-time error '-2147220975 (80040211)':
        The message could not be sent to the SMTP server. The transport error code was 0x800ccc15. The server response was not available.

        I am surprised to get this message because Outlook is already set up so I can send and recieve messages. Any suggestions? Thanks again! :)

        A 1 Reply Last reply
        0
        • H Harold_Wishes

          Hello, First, thanks for providing me this script. I ran it and everything seems to work fine until I run into the last line of code:

          objEmail.Send

          I get the following runtime error message:

          Run-time error '-2147220975 (80040211)':
          The message could not be sent to the SMTP server. The transport error code was 0x800ccc15. The server response was not available.

          I am surprised to get this message because Outlook is already set up so I can send and recieve messages. Any suggestions? Thanks again! :)

          A Offline
          A Offline
          Anoop Brijmohun
          wrote on last edited by
          #4

          no problem... If i am not mistaken, you will get this error if your SMTP address is incorrect or you might need to specify the Port Number to use. check outlook outgoing port and smtp addresses. hope this helps...let me know, will check in the morn ... Anoop :zzz:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups