Macro email

  • Thread starter Macro not running as intended
  • Start date
M

Macro not running as intended

I'm getting an error when I am using this macro:


Sub AA_CDO()
Dim iMsg As Object
Dim iConf As Object
' Dim Flds As Variant
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
' iConf.Load -1 ' CDO Source Defaults
' Set Flds = iConf.Fields
' With Flds
'
..Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
"(e-mail address removed)"
'
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
' .Update
' End With
With iMsg
Set .Configuration = iConf
.To = "(e-mail address removed); (e-mail address removed)"
.CC = "(e-mail address removed)"
.BCC = ""
.From = """Excel"" <[email protected]>"
.Subject = "Important message"
.TextBody = "AA has reached its stop loss" & vbNewLine & vbNewLine & _
"Please review this position immediately."
.Send
End With
Set iMsg = Nothing
Set iConf = Nothing
End Sub

Any thoughts?
 
M

Macro not running as intended

That is my smtp according to outlook...I did read your site and I'm trying to
get around the constant message approval. We have outlook and I'm not sure
exactly what year of windows. I thought I understood most everything on the
site, but maybe not.
 
M

Macro not running as intended

By commented lines do you mean the additional lines you have listed? Or did
I not change something I needed to?
 
R

Ron de Bruin

You must remove the ' for each commented line

Read this good on the site

************************************
Can you use CDO on your machine?

Let's try a basic example first.

The code below will send four text lines in the body of the mail to the person in this line
..To = "(e-mail address removed)"

Change (e-mail address removed) to your own mail address before you test the code.
If you read the information above you know that if you have a account in Outlook Express or
Windows Mail you can Run the code below after changing the mail address.
But if you not have a account in Outlook Express or Windows Mail you also need the commented
green lines in the code. Remove every ' before every green line and fill in the name of your SMTP server
where it says "Fill in your SMTP server here"

1) Open a new workbook
2) Alt F11 (to open the VBA editor)
3) Insert>Module
4) Paste the code in this module
5) Make your changes
6) Alt q to go back to Excel

When you use Alt F8 you can select the macro and press Run.
Now wait a moment and see if you receive the mail in your inbox.

Sub CDO_Mail_Small_Text()
Dim iMsg As Object
Dim iConf As Object
Dim strbody As String
' Dim Flds As Variant

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

' iConf.Load -1 ' CDO Source Defaults
' Set Flds = iConf.Fields
' With Flds
' .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
' .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
' = "Fill in your SMTP server here"
' .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
' .Update
' End With

strbody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2" & vbNewLine & _
"This is line 3" & vbNewLine & _
"This is line 4"

With iMsg
Set .Configuration = iConf
.To = "(e-mail address removed)"
.CC = ""
.BCC = ""
.From = """Ron"" <[email protected]>"
.Subject = "Important message"
.TextBody = strbody
.Send
End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top