Sending multiline email using a Excel 2011 on the mac

arShort

New Member
Joined
Jul 23, 2013
Messages
11
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
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,214,913
Messages
6,122,207
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top