VBA Email Body

ziad alsayed

Well-known Member
Joined
Jul 17, 2010
Messages
665
dear all

the below code is working perfectly, simply it is will the date and will give a message Box infoming about the person or persons Birhtday and finally send an email.
the problem i am facing is that the code is pasting the content of the Message Box as One Line , i want to be broken as per the MessageBox.

Example: insteat of stating " Today is ziad birthday, Tomorrow is Allen Birthday, Today is John Birthday"

i want to show in the Email as

Today is ziad birthday,

Tomorrow is Allen Birthday,

Today is John Birthday.


below is the code

Code:
Sub Birthday()
Dim finalRow As Long
Dim i As Long
Dim Msg As String
Dim omail As Object
Dim oapp As Object
Dim SigString As String
Dim Signature As String
    Msg = ""
    finalRow = Cells(Rows.Count, 1).End(xlUp).Row
    For i = 2 To finalRow
        If Cells(i, 2).Value = Date Then Msg = Msg & Cells(i, 1).Value & "'s" & " Birthday Is Today" & vbCrLf & vbCrLf
            If Cells(i, 3).Value = Date Then Msg = Msg & Cells(i, 1).Value & "'s" & " Birthday Is Tomorrow" & vbCrLf & vbCrLf
                If Cells(i, 4).Value = Date Then Msg = Msg & Cells(i, 1).Value & "'s" & " Birthday Is Next Tomorrow" & vbCrLf & vbCrLf
    Next i
        If Msg <> "" Then MsgBox Msg, , "Ziad Alsayed"
    Set oapp = CreateObject("outlook.application")
    Set omail = oapp.createitem(0)
' add the email Signature
    SigString = "c:\Users\Ziad Alsayed\AppData\Roaming\Microsoft\Signatures\Ziad.htm"
                If Dir(SigString) <> "" Then
                    Signature = GetBoiler(SigString)
                Else
                    Signature = ""
                End If
' start preparing to send the email
        With omail
            .To = "[EMAIL="Ziad.alsayed@jubailibros.com"]Ziad.alsayed@jubailibros.com[/EMAIL]"
            .Subject = " BirthDay E-Mail"
            Msg = Msg
            Msg = Msg & "<br><br>"
            .htmlbody = Msg & "<br><br>" & Signature
            .send
        End With
        
    Set omail = Nothing
    Set oapp = Nothing
    Application.DisplayAlerts = False
    Application.DisplayAlerts = True
End Sub
Function GetBoiler(ByVal sFile As String) As String
    Dim fso As Object
    Dim ts As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.getfile(sFile).OpenAstextstream(1, -2)
    GetBoiler = ts.readall
    ts.Close
End Function

appreciate any Help
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Copy the contents of a sent mail into notepad and see if there are any weird characters where the line breaks should be.

It's vaguely possible it's because you're using htmlbody.
 
Upvote 0
The only other thing is maybe it doesn't like sending in parts. Maybe make a new string variable that has the whole msg built in with vbcrlf in it and see if that works.

All VBA emails I use a single variable in the body.

Definaty need vbcrlf in there.

Oh as a thought. Can you use HTML code in there? Coz you could incorporate <br/> into the code
 
Upvote 0
The only other thing is maybe it doesn't like sending in parts. Maybe make a new string variable that has the whole msg built in with vbcrlf in it and see if that works.

All VBA emails I use a single variable in the body.

Definaty need vbcrlf in there.

Oh as a thought. Can you use HTML code in there? Coz you could incorporate
into the code


sorry didnt show. can incorporate a br into the vba code
 
Upvote 0
Hello,

Here is an example that may help:

<font face=Courier New>MsgBox "Top line" & vbNewLine & "Middle line" & vbNewLine & "Bottom line"</FONT>

Does that help?

-Jeff
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,839
Members
452,948
Latest member
UsmanAli786

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