Writing macro to send email

djdan

New Member
Joined
Apr 7, 2011
Messages
2
Code:
Sub Macro1()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    strbody = "Hi" & vbNewLine & vbNewLine & _
              "This email has been sent as notification that we are required to comply with regulations for the " & Range("arrangement").Value & " arrangement within 5 days of this email" & vbNewLine & _
              "Relevant Date: " & Format(Range("H28").Value, "dddd dd mmmm yyyy ") & vbNewLine & _
              "" & vbNewLine & _
              "Deadline to advise Users: " & Format(Range("H30").Value, "dddd dd mmmm yyyy ") & vbNewLine & _
              Range("arrangement").Value
    On Error Resume Next
    With OutMail
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = "requirement triggered"
        .Body = strbody
        .Send
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

Hi

I have created the above macro which I imagine is fairly common as I took it from a website (I think Ron de Bruin).

I added in the Range("arrangement").Value part so that the macro will inclue the text from the cell I have named 'arrangement'.

It all works very well, however, what I would like to do is to be able to adjust the font for different parts of the text. Especially the date:

Code:
& Format(Range("H30").Value, "dddd dd mmmm yyyy ") & vbNewLine & _

I have looked at code such as font.bold = true or Selection.font.bold = true but I can't get them to fit in anywhere that works, I think because of the .Value part.

Is there a simple way to modify the macro so I can make the changes?

If so... can I also ask how to include 'tab spaces' in the macro, so when viewing the email, certain text is aligned.

Thanks

Dan
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Dan,

As this is a format I believe you would be best to use HTML tags to add the format in your code.

I have seen that done here although I haven't had reason to do that myself.

Im sure this can be found here.
 
Upvote 0

Forum statistics

Threads
1,224,525
Messages
6,179,319
Members
452,905
Latest member
deadwings

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