VBA code to email active work book

P

PAG

Hi,

Is there some VBA code that I can use to be able to add text "Please provide
the accrued interest on the attached interfund trades. Thank you" to the body
of my email?

Dim wb As Workbook
Set wb = ActiveWorkbook

If Val(Application.Version) >= 12 Then
If wb.FileFormat = 51 And wb.HasVBProject = True Then
MsgBox "There is VBA code in this xlsx file, there will" &
vbNewLine & _
"be no VBA code in the file you send. Save the" &
vbNewLine & _
"file first as xlsm and then try the macro again.",
vbInformation
Exit Sub
End If
End If

On Error Resume Next
wb.SendMail "(e-mail address removed)", _
"Interfund Trade Accrued Interest"
On Error GoTo 0

End Sub


Thank you,

Peter
 
J

Jennifer

Hi,

Is there some VBA code that I can use to be able to add text "Please provide
the accrued interest on the attached interfund trades. Thank you" to the body
of my email?

Dim wb As Workbook
    Set wb = ActiveWorkbook

    If Val(Application.Version) >= 12 Then
        If wb.FileFormat = 51 And wb.HasVBProject = True Then
            MsgBox "There is VBA code in this xlsx file, there will" &
vbNewLine & _
                   "be no VBA code in the file you send. Save the" &
vbNewLine & _
                   "file first as xlsm and then try the macro again.",
vbInformation
            Exit Sub
        End If
    End If

    On Error Resume Next
    wb.SendMail "(e-mail address removed)", _
                "Interfund Trade Accrued Interest"
    On Error GoTo 0

  End Sub

Thank you,

Peter


With SendMail it is not possible to add text to the body of the
email. However, if you use CDO instead, you could do that. Below is
a simple example of doing this - adding an attachment and putting text
in the body of the email. Watch for word-wrap.

Jennifer


Dim wshnet
Dim compname

Set wshnet = CreateObject("wscript.network")
compname = wshnet.computername
Set iConf = CreateObject("CDO.Configuration")
Set iMsg = CreateObject("CDO.Message")
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/
smtpserver") = "mail" '"dev.smtp.wbhq.com"
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/
smtpport") = 25
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/
sendusing") = 2
iConf.Fields.Update

iMsg.Configuration = iConf
iMsg.From = "(e-mail address removed)"
iMsg.To = "(e-mail address removed)"
imsg.AddAttachment "C:\test.txt"
iMsg.Subject = "subject"
iMsg.TextBody = "this is a test"
iMsg.Send
 

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

Similar Threads

e-mail subject name changing 1
email conditions 2
Email 4
Excel 2003 3
Email Using CDO - mixed results 7
need help modifying ron de bruin email macro 1
Excel Sendmail Error.. Helppp!! 0
email via userfrom? 5

Top