title: Left Align embedded range in Email
body: <p>I'm having trouble getting a range that is embedded in an email to left align.  I've tried several things but the embedded portion still centers in the email.  Here is my code, which ironically, works just fine in other spreadsheets.  I've tried adding HTML tags, changing the function(s), all to no avail.  Any help would be appreciated. This is on W7x64 and Office 2010.  In this report I am embedding a pivot table instead of a regular range. </p>
  
  <p>Thanks.</p>
  
  <pre><code>Option Explicit
  
  SalesSub Mail_RegionalRANGE()
  
  Dim OutApp As Outlook.Application
  Dim OutMail As Outlook.MailItem
  
  
  'On Error Resume Next
  
      Set OutApp = CreateObject("outlook.application")
      Set OutMail = OutApp.CreateItem(olMailItem)
  
      With OutMail
          .SentOnBehalfOfName = "SalesAnalytics@company.us"
          .Display
          .Subject = "Sales Report"
          .To = "mike.marshall@company.us"
          '.CC =
          '.BCC =
          '.Attachments.Add "\\filesrv1\department shares\Sales Report\Sales Report.xlsx"
          .HTMLBody = "&lt;br&gt;" _
              &amp; "Attached is the Sales Report.  Please reach out to me with any questions." _
              &amp; "&lt;br&gt;&lt;br&gt;" _
              &amp; "&lt;p align=left&gt;" &amp; fncRangeToHtml("RegAEPctg", "B2:P67") &amp; "&lt;p&gt;" _
              &amp; .HTMLBody
  
          .Display
          '.Send
      End With
  
  
  Set OutApp = Nothing
  Set OutMail = Nothing
  
  End Sub
  
  
   Private Function fncRangeToHtml( _
   strWorksheetName As String, _
   strRangeAddress As String) As String
  
  
   Dim objFilesytem As Object, objTextstream As Object, objShape As Shape
   Dim strFilename As String, strTempText As String
   Dim blnRangeContainsShapes As Boolean
  
     Set objTextstream = Nothing
   Set objFilesytem = Nothing
  
   'Kill strFilename
  
  
   strFilename = Environ$("temp") &amp; "\" &amp; _
       Format(Now, "dd-mm-yy_h-mm-ss") &amp; ".htm"
  
   ThisWorkbook.PublishObjects.Add( _
       SourceType:=xlSourceRange, _
       Filename:=strFilename, _
       Sheet:=strWorksheetName, _
       Source:=strRangeAddress, _
       HtmlType:=xlHtmlStatic).Publish True
  
   Set objFilesytem = CreateObject("Scripting.FileSystemObject")
   Set objTextstream = objFilesytem.GetFile(strFilename).OpenAsTextStream(1, -2)
   strTempText = objTextstream.ReadAll
   objTextstream.Close
   strTempText = Replace(strTempText, "align=center x:publishsource=", "align=left x:publishsource=")
  
   For Each objShape In Worksheets(strWorksheetName).Shapes
       If Not Intersect(objShape.TopLeftCell, Worksheets( _
           strWorksheetName).Range(strRangeAddress)) Is Nothing Then
  
           blnRangeContainsShapes = True
           Exit For
  
       End If
   Next
  
   If blnRangeContainsShapes Then _
       strTempText = fncConvertPictureToMail(strTempText, Worksheets(strWorksheetName))
  
   fncRangeToHtml = strTempText
  
   Set objTextstream = Nothing
   Set objFilesytem = Nothing
  
   Kill strFilename
  
   End Function
  
  
   Public Function fncConvertPictureToMail(strTempText As String, objWorksheet As Worksheet) As String
  
   Const HTM_START = "&lt;link rel=File-List href="
   Const HTM_END = "/filelist.xml"
  
   Dim strTemp As String
   Dim lngPathLeft As Long
  
   lngPathLeft = InStr(1, strTempText, HTM_START)
  
   strTemp = Mid$(strTempText, lngPathLeft, InStr(lngPathLeft, strTempText, "&gt;") - lngPathLeft)
   strTemp = Replace(strTemp, HTM_START &amp; Chr$(34), "")
   strTemp = Replace(strTemp, HTM_END &amp; Chr$(34), "")
   strTemp = strTemp &amp; "/"
  
   strTempText = Replace(strTempText, strTemp, Environ$("temp") &amp; "\" &amp; strTemp)
  
   fncConvertPictureToMail = strTempText
  
   End Function
  </code></pre>