I am trying to send a multiline email using a macro in Excel 2011. The problem is that it isn't sending a separated lines it just ends up all bunched together.
Can anybody give me any help?
This is what I have right now
Sub MailBody()
'Generate Email Address
emadd = "" & UserName & "@grantpllc.com"
'Generate Subect Line
subl = "A payment was entered for " & proj & ""
'Generate Body
sMsgBody = "Dear " & firstname & "," & vbCr
sMsgBody = sMsgBody & "The following payment has been received and recorded for a project for which you are listed as Project Manager." & vbCr
sMsgBody = sMsgBody & "Client: " & clt & "" & vbCr
sMsgBody = sMsgBody & "Project: " & proj & "" & vbCr
If Not chk = "" Then
sMsgBody = sMsgBody & "Payment Type: Cheque" & vbCr
Else
sMsgBody = sMsgBody & "Payment Type: Wire" & vbCr
End If
sMsgBody = sMsgBody & "Amount : $ " & amt & "" & vbCr
If Not desc = "" Then
sMsgBody = sMsgBody & "Description: " & desc & "" & vbCr
End If
sMsgBody = sMsgBody & "Regards," & vbCr
sMsgBody = sMsgBody & "Finance Team"
mbody = sMsgBody
End Sub
Sub MailSend()
'For Excel 2011 for the Mac and Apple Mail
'Note: The workbook must be saved once
Dim wb As Workbook
If Val(Application.Version) < 14 Then Exit Sub
Set wb = ActiveWorkbook
With wb
MailFromMacwithOutlook bodycontent:=mbody, _
mailsubject:=subl, _
toaddress:=emadd, _
ccaddress:="", _
bccaddress:="", _
attachment:="", _
displaymail:=False
End With
Set wb = Nothing
End Sub
Function MailFromMacwithOutlook(bodycontent As String, mailsubject As String, _
toaddress As String, ccaddress As String, bccaddress As String, _
attachment As String, displaymail As Boolean)
Dim scriptToRun As String
scriptToRun = scriptToRun & "tell application " & _
Chr(34) & "Microsoft Outlook" & Chr(34) & Chr(13)
scriptToRun = scriptToRun & _
"set NewMail to make new outgoing message with properties" & _
"{content:""" & bodycontent & """, subject:""" & mailsubject & """}" & Chr(13)
If toaddress <> "" Then scriptToRun = scriptToRun & _
"make new to recipient at NewMail with properties" & _
"{email address:{address:""" & toaddress & """}}" & Chr(13)
If ccaddress <> "" Then scriptToRun = scriptToRun & _
"make new cc recipient at NewMail with properties" & _
"{email address:{address:""" & ccaddress & """}}" & Chr(13)
If bccaddress <> "" Then scriptToRun = scriptToRun & _
"make new bcc recipient at NewMail with properties" & _
"{email address:{address:""" & bccaddress & """}}" & Chr(13)
If attachment <> "" Then
scriptToRun = scriptToRun & "make new attachment at NewMail with properties" & _
"{file:""" & attachment & """ as alias}" & Chr(13)
End If
If displaymail = False Then
scriptToRun = scriptToRun & "send NewMail" & Chr(13)
Else
scriptToRun = scriptToRun & "open NewMail" & Chr(13)
End If
scriptToRun = scriptToRun & "end tell" & Chr(13)
If Len(toaddress) + Len(ccaddress) + Len(bccaddress) = 0 Or mailsubject = "" Then
MsgBox "There is no To, CC or BCC address or Subject for this mail"
Exit Function
Else
On Error Resume Next
MacScript (scriptToRun)
On Error GoTo 0
End If
End Function
Function KillFileOnMac(Filestr As String)
'The VBA Kill command on a Mac will not work with long file names(28+ characters)
Dim ScriptToKillFile As String
ScriptToKillFile = ScriptToKillFile & "tell application " & Chr(34) & _
"Finder" & Chr(34) & Chr(13)
ScriptToKillFile = ScriptToKillFile & _
"do shell script ""rm "" & quoted form of posix path of " & _
Chr(34) & Filestr & Chr(34) & Chr(13)
ScriptToKillFile = ScriptToKillFile & "end tell"
On Error Resume Next
MacScript (ScriptToKillFile)
On Error GoTo 0
End Function
Can anybody give me any help?
This is what I have right now
Sub MailBody()
'Generate Email Address
emadd = "" & UserName & "@grantpllc.com"
'Generate Subect Line
subl = "A payment was entered for " & proj & ""
'Generate Body
sMsgBody = "Dear " & firstname & "," & vbCr
sMsgBody = sMsgBody & "The following payment has been received and recorded for a project for which you are listed as Project Manager." & vbCr
sMsgBody = sMsgBody & "Client: " & clt & "" & vbCr
sMsgBody = sMsgBody & "Project: " & proj & "" & vbCr
If Not chk = "" Then
sMsgBody = sMsgBody & "Payment Type: Cheque" & vbCr
Else
sMsgBody = sMsgBody & "Payment Type: Wire" & vbCr
End If
sMsgBody = sMsgBody & "Amount : $ " & amt & "" & vbCr
If Not desc = "" Then
sMsgBody = sMsgBody & "Description: " & desc & "" & vbCr
End If
sMsgBody = sMsgBody & "Regards," & vbCr
sMsgBody = sMsgBody & "Finance Team"
mbody = sMsgBody
End Sub
Sub MailSend()
'For Excel 2011 for the Mac and Apple Mail
'Note: The workbook must be saved once
Dim wb As Workbook
If Val(Application.Version) < 14 Then Exit Sub
Set wb = ActiveWorkbook
With wb
MailFromMacwithOutlook bodycontent:=mbody, _
mailsubject:=subl, _
toaddress:=emadd, _
ccaddress:="", _
bccaddress:="", _
attachment:="", _
displaymail:=False
End With
Set wb = Nothing
End Sub
Function MailFromMacwithOutlook(bodycontent As String, mailsubject As String, _
toaddress As String, ccaddress As String, bccaddress As String, _
attachment As String, displaymail As Boolean)
Dim scriptToRun As String
scriptToRun = scriptToRun & "tell application " & _
Chr(34) & "Microsoft Outlook" & Chr(34) & Chr(13)
scriptToRun = scriptToRun & _
"set NewMail to make new outgoing message with properties" & _
"{content:""" & bodycontent & """, subject:""" & mailsubject & """}" & Chr(13)
If toaddress <> "" Then scriptToRun = scriptToRun & _
"make new to recipient at NewMail with properties" & _
"{email address:{address:""" & toaddress & """}}" & Chr(13)
If ccaddress <> "" Then scriptToRun = scriptToRun & _
"make new cc recipient at NewMail with properties" & _
"{email address:{address:""" & ccaddress & """}}" & Chr(13)
If bccaddress <> "" Then scriptToRun = scriptToRun & _
"make new bcc recipient at NewMail with properties" & _
"{email address:{address:""" & bccaddress & """}}" & Chr(13)
If attachment <> "" Then
scriptToRun = scriptToRun & "make new attachment at NewMail with properties" & _
"{file:""" & attachment & """ as alias}" & Chr(13)
End If
If displaymail = False Then
scriptToRun = scriptToRun & "send NewMail" & Chr(13)
Else
scriptToRun = scriptToRun & "open NewMail" & Chr(13)
End If
scriptToRun = scriptToRun & "end tell" & Chr(13)
If Len(toaddress) + Len(ccaddress) + Len(bccaddress) = 0 Or mailsubject = "" Then
MsgBox "There is no To, CC or BCC address or Subject for this mail"
Exit Function
Else
On Error Resume Next
MacScript (scriptToRun)
On Error GoTo 0
End If
End Function
Function KillFileOnMac(Filestr As String)
'The VBA Kill command on a Mac will not work with long file names(28+ characters)
Dim ScriptToKillFile As String
ScriptToKillFile = ScriptToKillFile & "tell application " & Chr(34) & _
"Finder" & Chr(34) & Chr(13)
ScriptToKillFile = ScriptToKillFile & _
"do shell script ""rm "" & quoted form of posix path of " & _
Chr(34) & Filestr & Chr(34) & Chr(13)
ScriptToKillFile = ScriptToKillFile & "end tell"
On Error Resume Next
MacScript (ScriptToKillFile)
On Error GoTo 0
End Function