title: Text wrapping in Outlook while using Range to HTML Conversion with Excel VBA
body: <p>I am trying to format <code>.HTMLbody</code> in email in a way to put an image containing a chart next to table with the data based on which the chart was created.</p>
  
  <p>To convert the range with data into HTML I use Ron de Bruin's Range to HTML code.</p>
  
  <p>My goal is to get mail body like below:
  <img src="https://i.stack.imgur.com/VCPZm.png" alt="Result to achieve"></p>
  
  <p>I am getting this:
  <img src="https://i.stack.imgur.com/VPyTM.png" alt="What i have now"></p>
  
  <p>My code.</p>
  
  <pre><code>Private Sub SendingMail()
  
      Dim OutApp As Object, OutMail As Object
      Dim strPic1 As String
      Dim strPic1Inserting As String
      Dim strTextOfMessage As String
  
      strTextOfMessage = "&lt;p style='font-family:arial;font-size:10pt'&gt;" &amp; "Hello ,&lt;br&gt;&lt;br&gt;Please Find Report Attached.&lt;br&gt;&lt;br&gt;In case of any questions please do not hesitate to contact us." &amp; "&lt;/p&gt;"
      ActiveWorkbook.Worksheets("1").ChartObjects("Wykres 1").Chart.Export SCIEZKARAPORT &amp; "TempPicture.png"
      strPic1 = SCIEZKARAPORT &amp; "TempPicture.png"
      strPic1Inserting = "&lt;br/&gt;" &amp; "&lt;img src='cid:" &amp; "TempPicture.png" &amp; "' height=250 width=500&gt;" &amp; "&lt;br/&gt;&lt;br/&gt;"
  
      Set OutApp = CreateObject("Outlook.Application")
      Set OutMail = OutApp.CreateItem(0)
  
      With OutMail
          .Display
          .To = ""
          .CC = ""
          .Subject = ""
          .Attachments.Add strPic1
          .HTMLBody = strTextOfMessage &amp; RangetoHTML(Range("qqq")) &amp; strPic1Inserting &amp; "&lt;br&gt;" &amp; .HTMLBody
          .Display
      End With
  
      Set OutMail = Nothing
      Set OutApp = Nothing
  End Sub
  
  
  Function RangetoHTML(rng As Range)
  
  ' Changed by Ron de Bruin 28-Oct-2006
  ' Working in Office 2000-2016
  
      Dim fso As Object
      Dim ts As Object
      Dim TempFile As String
      Dim TempWB As Workbook
  
      TempFile = Environ$("temp") &amp; "\" &amp; Format(Now, "dd-mm-yy h-mm-ss") &amp; ".htm"
  
      'Copy the range and create a new workbook to past the data in
      rng.Copy
      Set TempWB = Workbooks.Add(1)
      With TempWB.Sheets(1)
          .Cells(1).PasteSpecial Paste:=8
          .Cells(1).PasteSpecial xlPasteValues, , False, False
          .Cells(1).PasteSpecial xlPasteFormats, , False, False
          .Cells(1).Select
          Application.CutCopyMode = False
          On Error Resume Next
          .DrawingObjects.Visible = True
          .DrawingObjects.Delete
          On Error GoTo 0
      End With
  
      'Publish the sheet to a htm file
      With TempWB.PublishObjects.Add( _
           SourceType:=xlSourceRange, _
           FileName:=TempFile, _
           Sheet:=TempWB.Sheets(1).Name, _
           Source:=TempWB.Sheets(1).UsedRange.Address, _
           HtmlType:=xlHtmlStatic)
          .Publish (True)
      End With
  
      'Read all data from the htm file into RangetoHTML
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
      RangetoHTML = ts.readall
      ts.Close
      RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
                            "align=left x:publishsource=")
  
      'Close TempWB
      TempWB.Close savechanges:=False
  
      'Delete the htm file we used in this function
      Kill TempFile
  
      Set ts = Nothing
      Set fso = Nothing
      Set TempWB = Nothing
  End Function
  </code></pre>
  
  <p>Solution:<br>
  Unfortunately <code>&lt;div&gt;</code> tags did not work for me. But when investigating why this might be, I found a post stating that <code>&lt;table&gt;</code> tags might do just that. I achieved what I was hoping for using the line below:</p>
  
  <pre><code>.HTMLBody = strTextOfMessage &amp; "&lt;table align='left'&gt;" &amp; RangetoHTML(Range("www")) &amp; "&lt;/table&gt;" &amp; strPic1Inserting &amp; "&lt;br clear='left'&gt;&lt;br&gt;" &amp; .HTMLBody
  </code></pre>