Posts Tagged Subject

Hello all. I had a production manager wanting an excel spreadsheet mailed as the body of the email. As some of you know the code generated by excel to produce the email is pretty crazy. But as a result, it showed up fine in Outlook and Android but it did not show the gridlines on the spreadsheet. So this code is based on the excellent work by Ron DeBruin over at http://www.rondebruin.nl/win/s1/outlook/bmail3.htm . I did a replacement for the HTML Range in this manner and the grid lines did appear. And the manager was happy.

Sub Mail_Selection_Range_Outlook_Body()‘For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm‘Don’t forget to copy the function RangetoHTML in the module.‘Working in Excel 2000-2016 Dim rng As Range Dim OutApp As Object Dim OutMail As Object‘MsgBox Cells(5, 9).Value Set rng = Nothing On Error Resume Next ‘Only the visible cells in the selection Set rng = Selection.SpecialCells(xlCellTypeVisible) ‘You can also use a fixed range if you want ‘Set rng = Sheets(“YourSheet”).Range(“D4:D12”).SpecialCells(xlCellTypeVisible) On Error GoTo 0

If rng Is Nothing Then MsgBox “The selection is not a range or the sheet is protected” & _ vbNewLine & “please correct and try again.”, vbOKOnly Exit Sub End If

With Application .EnableEvents = False .ScreenUpdating = False End With