Vba code olMail.body from Excel to Outlook

ddarecki

New Member
Joined
Aug 20, 2011
Messages
2
First of all, thank you in advance for helping me out with my dilemma,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
I have the following code that exports certain cell values, along with message from excel to outlook. It works great, provided that there are values in all those cells mentioned in the code. How do I re-write it to work even when some of the cells are blank?<o:p></o:p>
<o:p> </o:p>
Public Sub Test777()

Dim olApp As Object, olMail As Object
Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(0)
olMail.To = "someone@yahoo.com"
olMail.Subject = "Mfg Shift Report"
olMail.body = "Line " & Range("A4") & " - " & Range("B4") & " - " & Range("C4") & " = " & Range("S4") & " Cases - " & Range("W4") & " % of Line Efficiency; " & Range("AC4") & " Minutes Down Time; " & Range("AE4") & " " & "Lbs - " & Range("AF4") & " % of Scrap." _
& Chr(13) & "Line " & Range("A5") & " - " & Range("B5") & " - " & Range("C5") & " = " & Range("S5") & " Cases - " & Range("W5") & " % of Line Efficiency; " & Range("AC5") & " Minutes Down Time; " & Range("AE5") & " " & "Lbs - " & Range("AF5") & " % of Scrap." _
& Chr(13) & "Line " & Range("A6") & " - " & Range("B6") & " - " & Range("C6") & " = " & Range("S6") & " Cases - " & Range("W6") & " % of Line Efficiency; " & Range("AC6") & " Minutes Down Time; " & Range("AE6") & " " & "Lbs - " & Range("AF6") & " % of Scrap." _
& Chr(13) & "Line " & Range("A7") & " - " & Range("B7") & " - " & Range("C7") & " = " & Range("S7") & " Cases - " & Range("W7") & " % of Line Efficiency; " & Range("AC7") & " Minutes Down Time; " & Range("AE7") & " " & "Lbs - " & Range("AF7") & " % of Scrap." _
& Chr(13) & "Line " & Range("A8") & " - " & Range("B8") & " - " & Range("C8") & " = " & Range("S8") & " Cases - " & Range("W8") & " % of Line Efficiency; " & Range("AC8") & " Minutes Down Time; " & Range("AE8") & " " & "Lbs - " & Range("AF8") & " % of Scrap."

olMail.Display

AppActivate "Microsoft Excel"

End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,224,542
Messages
6,179,421
Members
452,913
Latest member
JWD210

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