title: How to align HtmlBody Right-to -Left when sending a cell range using excel VBA via outlook
body: <p>I have a cell range that I need to send via outlook using VBA.</p>
  
  <p>I'm using this code to convert the range to HTML:</p>
  
  <pre><code>    Function rangetoHTML(rng As Range)
      ' Changed by Ron de Bruin 28-Oct-2006
      ' Working in Office 2000-2013
  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=right 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>And I'm using this code to generate the outlook window with the data I need:</p>
  
  <pre><code>Sub Trigger_Email()
  Dim rng As Range
  Dim rng2 As Range
  Dim OutApp As Object
  Dim OutMail As Object
  Dim StrBody As String
  
  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 = Range("A1:K42").SpecialCells(xlCellTypeVisible)
  On Error GoTo 0
  
  If rng Is Nothing Then
      MsgBox "The selection is not a range or the sheet is protected" &amp; _
             vbNewLine &amp; "please correct and try again.", vbOKOnly
      Exit Sub
  End If
  
  With Application
      .EnableEvents = False
      .ScreenUpdating = False
  End With
  
  Set OutApp = CreateObject("Outlook.Application")
  Set OutMail = OutApp.CreateItem(0)
  
  On Error Resume Next
  
  
  
  With OutMail
      .To = ""
      .Subject = Range("D16")
      .HTMLBody = rangetoHTML(rng)
      .Attachments.Add "u:\temp.txt"
      .Display   'or use .Display
  End With
  On Error GoTo 0
  
  With Application
      .EnableEvents = True
      .ScreenUpdating = True
  End With
  
  Set OutMail = Nothing
  Set OutApp = Nothing
  End Sub
  </code></pre>
  
  <p>The Issue I'm having is that when i'm executing the program, the email that is generated in left-to-right but as my data and design are in Hebrew so it messes-up the email, and for some reason the workbook alignment turns left-to-right as well.</p>
  
  <p>my coding skills in VBA are limited, I spent well over three days researching and trying to solve this myself, and couldn't.
  I'l appreciate any help.</p>
  
  <p>Dan.</p>