Sending Email using VBA in Word
-
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! :)
-
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! :)
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
-
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
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! :)
-
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! :)
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: