Okay so I am having a problem. If you enter this code (below) in a VBA module you will have the desired text show up in the email body and to the desired recipients (yay). HOWEVER, I need to find a way to have my formatted text appear as it is in excel. ie bolded and underlined at certain points.
Please, any suggestions would be greatly appreciated. (if you can get it to work, maybe just paste in the new code?)
Sub CreateMail()
Dim doData1 As DataObject, doData2 As DataObject
Dim objOutlook As Object, objMail As Object
Dim rngTo As Range, rngCc As Range, rngSubject As Range
Dim rngBody1 As Range, rngBody2 As Range
Set doData1 = New DataObject
Set doData2 = New DataObject
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
With Sheets("Sheet1")
Set rngTo = .Range("D2")
Set rngCc = .Range("D3")
Set rngSubject = .Range("H1")
End With
'This is the selection for the body of the email.
Set rngBody1 = Sheets("Sheet1").Range("A1:C10")
rngBody1.Copy
doData1.GetFromClipboard
'I unlock these if I want to add data from another sheet or a new range from the same sheet
'Set rngBody2 = Sheets("Sheet3").Range("B1")
'rngBody2.Copy
'doData2.GetFromClipboard
With objMail
.To = rngTo.Value
.CC = rngCc.Value
.Subject = rngSubject.Value
.Body = doData1.GetText(1) '(this section is locked and unlocked if I want to use a second range) & vbCrLf & doData2.GetText(1)
.Send
End With
Set doData1 = Nothing
Set doData2 = Nothing
Set objOutlook = Nothing
Set objMail = Nothing
Set rngTo = Nothing
Set rngCc = Nothing
Set rngSubject = Nothing
Set rngBody1 = Nothing
Set rngBody2 = Nothing
End Sub
Please, any suggestions would be greatly appreciated. (if you can get it to work, maybe just paste in the new code?)
Sub CreateMail()
Dim doData1 As DataObject, doData2 As DataObject
Dim objOutlook As Object, objMail As Object
Dim rngTo As Range, rngCc As Range, rngSubject As Range
Dim rngBody1 As Range, rngBody2 As Range
Set doData1 = New DataObject
Set doData2 = New DataObject
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
With Sheets("Sheet1")
Set rngTo = .Range("D2")
Set rngCc = .Range("D3")
Set rngSubject = .Range("H1")
End With
'This is the selection for the body of the email.
Set rngBody1 = Sheets("Sheet1").Range("A1:C10")
rngBody1.Copy
doData1.GetFromClipboard
'I unlock these if I want to add data from another sheet or a new range from the same sheet
'Set rngBody2 = Sheets("Sheet3").Range("B1")
'rngBody2.Copy
'doData2.GetFromClipboard
With objMail
.To = rngTo.Value
.CC = rngCc.Value
.Subject = rngSubject.Value
.Body = doData1.GetText(1) '(this section is locked and unlocked if I want to use a second range) & vbCrLf & doData2.GetText(1)
.Send
End With
Set doData1 = Nothing
Set doData2 = Nothing
Set objOutlook = Nothing
Set objMail = Nothing
Set rngTo = Nothing
Set rngCc = Nothing
Set rngSubject = Nothing
Set rngBody1 = Nothing
Set rngBody2 = Nothing
End Sub