Excel selected range to Outlook email body - Formatting problem












0














I spent few hours looking for help on the forum. But my level of VBA is not on such level that I would be able to implement and test the changes in code.



In short, I have an excel file and I want to send Range selected via outlook email.
Many tutorials here and this is working fine.



But my trouble is the formatting.
No matter how I try the row height in the outlook email keeps messing up and graphs are overlapping the tables etc. The rows width and object positions are ok though.



So is there any trick, how to keep the formatting exactly the same as in the excel file?



Here is the code for sending the range via email which is working:



Private Sub Workbook_Open()

ActiveWorkbook.RefreshAll

'Working in Excel 2002-2016
Dim AWorksheet As Worksheet
Dim Sendrng As Range
Dim rng As Range

Sheets("Data").Select

On Error GoTo StopMacro

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

'Fill in the Worksheet/range you want to mail
'Note: if you use one cell it will send the whole worksheet
Set Sendrng = Worksheets("Data").Range("A1:S600")

'Remember the activesheet
Set AWorksheet = ActiveSheet

With Sendrng

'Select the worksheet with the range you want to send
.Parent.Select

'Remember the ActiveCell on that worksheet
Set rng = ActiveCell

'Select the range you want to mail
.Select

' Create the mail and send it
ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope

' Set the optional introduction field thats adds
' some header text to the email body.
'.Introduction = "Hello all."

With .Item
.To = "xxx@zzz.eu"
.CC = "xxx@zzz.eu"
.BCC = ""
.Subject = "xxx" & Format(Worksheets("Support").Range("A1").Value, "dd.mm.yyyy")
.Send
End With

End With

'select the original ActiveCell
rng.Select
End With

'Activate the sheet that was active before you run the macro
AWorksheet.Select

StopMacro:
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
ActiveWorkbook.EnvelopeVisible = False

ActiveWorkbook.Save
Application.Quit

End Sub









share|improve this question





























    0














    I spent few hours looking for help on the forum. But my level of VBA is not on such level that I would be able to implement and test the changes in code.



    In short, I have an excel file and I want to send Range selected via outlook email.
    Many tutorials here and this is working fine.



    But my trouble is the formatting.
    No matter how I try the row height in the outlook email keeps messing up and graphs are overlapping the tables etc. The rows width and object positions are ok though.



    So is there any trick, how to keep the formatting exactly the same as in the excel file?



    Here is the code for sending the range via email which is working:



    Private Sub Workbook_Open()

    ActiveWorkbook.RefreshAll

    'Working in Excel 2002-2016
    Dim AWorksheet As Worksheet
    Dim Sendrng As Range
    Dim rng As Range

    Sheets("Data").Select

    On Error GoTo StopMacro

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

    'Fill in the Worksheet/range you want to mail
    'Note: if you use one cell it will send the whole worksheet
    Set Sendrng = Worksheets("Data").Range("A1:S600")

    'Remember the activesheet
    Set AWorksheet = ActiveSheet

    With Sendrng

    'Select the worksheet with the range you want to send
    .Parent.Select

    'Remember the ActiveCell on that worksheet
    Set rng = ActiveCell

    'Select the range you want to mail
    .Select

    ' Create the mail and send it
    ActiveWorkbook.EnvelopeVisible = True
    With .Parent.MailEnvelope

    ' Set the optional introduction field thats adds
    ' some header text to the email body.
    '.Introduction = "Hello all."

    With .Item
    .To = "xxx@zzz.eu"
    .CC = "xxx@zzz.eu"
    .BCC = ""
    .Subject = "xxx" & Format(Worksheets("Support").Range("A1").Value, "dd.mm.yyyy")
    .Send
    End With

    End With

    'select the original ActiveCell
    rng.Select
    End With

    'Activate the sheet that was active before you run the macro
    AWorksheet.Select

    StopMacro:
    With Application
    .ScreenUpdating = True
    .EnableEvents = True
    End With
    ActiveWorkbook.EnvelopeVisible = False

    ActiveWorkbook.Save
    Application.Quit

    End Sub









    share|improve this question



























      0












      0








      0







      I spent few hours looking for help on the forum. But my level of VBA is not on such level that I would be able to implement and test the changes in code.



      In short, I have an excel file and I want to send Range selected via outlook email.
      Many tutorials here and this is working fine.



      But my trouble is the formatting.
      No matter how I try the row height in the outlook email keeps messing up and graphs are overlapping the tables etc. The rows width and object positions are ok though.



      So is there any trick, how to keep the formatting exactly the same as in the excel file?



      Here is the code for sending the range via email which is working:



      Private Sub Workbook_Open()

      ActiveWorkbook.RefreshAll

      'Working in Excel 2002-2016
      Dim AWorksheet As Worksheet
      Dim Sendrng As Range
      Dim rng As Range

      Sheets("Data").Select

      On Error GoTo StopMacro

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

      'Fill in the Worksheet/range you want to mail
      'Note: if you use one cell it will send the whole worksheet
      Set Sendrng = Worksheets("Data").Range("A1:S600")

      'Remember the activesheet
      Set AWorksheet = ActiveSheet

      With Sendrng

      'Select the worksheet with the range you want to send
      .Parent.Select

      'Remember the ActiveCell on that worksheet
      Set rng = ActiveCell

      'Select the range you want to mail
      .Select

      ' Create the mail and send it
      ActiveWorkbook.EnvelopeVisible = True
      With .Parent.MailEnvelope

      ' Set the optional introduction field thats adds
      ' some header text to the email body.
      '.Introduction = "Hello all."

      With .Item
      .To = "xxx@zzz.eu"
      .CC = "xxx@zzz.eu"
      .BCC = ""
      .Subject = "xxx" & Format(Worksheets("Support").Range("A1").Value, "dd.mm.yyyy")
      .Send
      End With

      End With

      'select the original ActiveCell
      rng.Select
      End With

      'Activate the sheet that was active before you run the macro
      AWorksheet.Select

      StopMacro:
      With Application
      .ScreenUpdating = True
      .EnableEvents = True
      End With
      ActiveWorkbook.EnvelopeVisible = False

      ActiveWorkbook.Save
      Application.Quit

      End Sub









      share|improve this question















      I spent few hours looking for help on the forum. But my level of VBA is not on such level that I would be able to implement and test the changes in code.



      In short, I have an excel file and I want to send Range selected via outlook email.
      Many tutorials here and this is working fine.



      But my trouble is the formatting.
      No matter how I try the row height in the outlook email keeps messing up and graphs are overlapping the tables etc. The rows width and object positions are ok though.



      So is there any trick, how to keep the formatting exactly the same as in the excel file?



      Here is the code for sending the range via email which is working:



      Private Sub Workbook_Open()

      ActiveWorkbook.RefreshAll

      'Working in Excel 2002-2016
      Dim AWorksheet As Worksheet
      Dim Sendrng As Range
      Dim rng As Range

      Sheets("Data").Select

      On Error GoTo StopMacro

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

      'Fill in the Worksheet/range you want to mail
      'Note: if you use one cell it will send the whole worksheet
      Set Sendrng = Worksheets("Data").Range("A1:S600")

      'Remember the activesheet
      Set AWorksheet = ActiveSheet

      With Sendrng

      'Select the worksheet with the range you want to send
      .Parent.Select

      'Remember the ActiveCell on that worksheet
      Set rng = ActiveCell

      'Select the range you want to mail
      .Select

      ' Create the mail and send it
      ActiveWorkbook.EnvelopeVisible = True
      With .Parent.MailEnvelope

      ' Set the optional introduction field thats adds
      ' some header text to the email body.
      '.Introduction = "Hello all."

      With .Item
      .To = "xxx@zzz.eu"
      .CC = "xxx@zzz.eu"
      .BCC = ""
      .Subject = "xxx" & Format(Worksheets("Support").Range("A1").Value, "dd.mm.yyyy")
      .Send
      End With

      End With

      'select the original ActiveCell
      rng.Select
      End With

      'Activate the sheet that was active before you run the macro
      AWorksheet.Select

      StopMacro:
      With Application
      .ScreenUpdating = True
      .EnableEvents = True
      End With
      ActiveWorkbook.EnvelopeVisible = False

      ActiveWorkbook.Save
      Application.Quit

      End Sub






      excel vba email outlook






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 14:54









      James Z

      11.1k71735




      11.1k71735










      asked Nov 19 '18 at 12:36









      KAdman

      1




      1
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You could refer to the below code:



          Function RangetoHTMLFlexWidth(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") & "" & Format(Now, "dd-mm-yy h-mm-ss") & ".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)
          RangetoHTMLFlexWidth = ts.readall
          ts.Close
          RangetoHTMLFlexWidth = Replace(RangetoHTMLFlexWidth, "align=center x:publishsource=", _
          "align=left x:publishsource=")

          Dim startIndex As Long
          Dim stopIndex As Long
          Dim subString As String

          'Change table width to "100%"
          startIndex = InStr(RangetoHTMLFlexWidth, "<table")
          startIndex = InStr(startIndex, RangetoHTMLFlexWidth, "width:") + 5
          stopIndex = InStr(startIndex, RangetoHTMLFlexWidth, "'>")
          subString = Left(RangetoHTMLFlexWidth, startIndex)
          subString = subString & "100%"
          RangetoHTMLFlexWidth = subString & Mid(RangetoHTMLFlexWidth, stopIndex)

          '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


          For more information, please refer to the below link:



          Send Excel range into Email body with autofit






          share|improve this answer





















          • Thank you, this works fine. But there is trouble with sending Graphs, they are not included in the selection.
            – KAdman
            Nov 20 '18 at 14:41












          • Maybe this link will help for you:stackoverflow.com/questions/27042842/…
            – Alina Li
            Nov 21 '18 at 9:26










          • Well, ok in case I will resign to the sending the whole thing (Range A1:X600) as a picture. This code would work, but the image disturbe the text in the graphs and bold text in tables so it is unreadable. Realy the best way would be to just use the MailEnvelope attitude, but with some condition that it will keep the positions of graphs and the hight of rows.
            – KAdman
            Nov 23 '18 at 9:20











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374822%2fexcel-selected-range-to-outlook-email-body-formatting-problem%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You could refer to the below code:



          Function RangetoHTMLFlexWidth(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") & "" & Format(Now, "dd-mm-yy h-mm-ss") & ".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)
          RangetoHTMLFlexWidth = ts.readall
          ts.Close
          RangetoHTMLFlexWidth = Replace(RangetoHTMLFlexWidth, "align=center x:publishsource=", _
          "align=left x:publishsource=")

          Dim startIndex As Long
          Dim stopIndex As Long
          Dim subString As String

          'Change table width to "100%"
          startIndex = InStr(RangetoHTMLFlexWidth, "<table")
          startIndex = InStr(startIndex, RangetoHTMLFlexWidth, "width:") + 5
          stopIndex = InStr(startIndex, RangetoHTMLFlexWidth, "'>")
          subString = Left(RangetoHTMLFlexWidth, startIndex)
          subString = subString & "100%"
          RangetoHTMLFlexWidth = subString & Mid(RangetoHTMLFlexWidth, stopIndex)

          '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


          For more information, please refer to the below link:



          Send Excel range into Email body with autofit






          share|improve this answer





















          • Thank you, this works fine. But there is trouble with sending Graphs, they are not included in the selection.
            – KAdman
            Nov 20 '18 at 14:41












          • Maybe this link will help for you:stackoverflow.com/questions/27042842/…
            – Alina Li
            Nov 21 '18 at 9:26










          • Well, ok in case I will resign to the sending the whole thing (Range A1:X600) as a picture. This code would work, but the image disturbe the text in the graphs and bold text in tables so it is unreadable. Realy the best way would be to just use the MailEnvelope attitude, but with some condition that it will keep the positions of graphs and the hight of rows.
            – KAdman
            Nov 23 '18 at 9:20
















          0














          You could refer to the below code:



          Function RangetoHTMLFlexWidth(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") & "" & Format(Now, "dd-mm-yy h-mm-ss") & ".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)
          RangetoHTMLFlexWidth = ts.readall
          ts.Close
          RangetoHTMLFlexWidth = Replace(RangetoHTMLFlexWidth, "align=center x:publishsource=", _
          "align=left x:publishsource=")

          Dim startIndex As Long
          Dim stopIndex As Long
          Dim subString As String

          'Change table width to "100%"
          startIndex = InStr(RangetoHTMLFlexWidth, "<table")
          startIndex = InStr(startIndex, RangetoHTMLFlexWidth, "width:") + 5
          stopIndex = InStr(startIndex, RangetoHTMLFlexWidth, "'>")
          subString = Left(RangetoHTMLFlexWidth, startIndex)
          subString = subString & "100%"
          RangetoHTMLFlexWidth = subString & Mid(RangetoHTMLFlexWidth, stopIndex)

          '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


          For more information, please refer to the below link:



          Send Excel range into Email body with autofit






          share|improve this answer





















          • Thank you, this works fine. But there is trouble with sending Graphs, they are not included in the selection.
            – KAdman
            Nov 20 '18 at 14:41












          • Maybe this link will help for you:stackoverflow.com/questions/27042842/…
            – Alina Li
            Nov 21 '18 at 9:26










          • Well, ok in case I will resign to the sending the whole thing (Range A1:X600) as a picture. This code would work, but the image disturbe the text in the graphs and bold text in tables so it is unreadable. Realy the best way would be to just use the MailEnvelope attitude, but with some condition that it will keep the positions of graphs and the hight of rows.
            – KAdman
            Nov 23 '18 at 9:20














          0












          0








          0






          You could refer to the below code:



          Function RangetoHTMLFlexWidth(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") & "" & Format(Now, "dd-mm-yy h-mm-ss") & ".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)
          RangetoHTMLFlexWidth = ts.readall
          ts.Close
          RangetoHTMLFlexWidth = Replace(RangetoHTMLFlexWidth, "align=center x:publishsource=", _
          "align=left x:publishsource=")

          Dim startIndex As Long
          Dim stopIndex As Long
          Dim subString As String

          'Change table width to "100%"
          startIndex = InStr(RangetoHTMLFlexWidth, "<table")
          startIndex = InStr(startIndex, RangetoHTMLFlexWidth, "width:") + 5
          stopIndex = InStr(startIndex, RangetoHTMLFlexWidth, "'>")
          subString = Left(RangetoHTMLFlexWidth, startIndex)
          subString = subString & "100%"
          RangetoHTMLFlexWidth = subString & Mid(RangetoHTMLFlexWidth, stopIndex)

          '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


          For more information, please refer to the below link:



          Send Excel range into Email body with autofit






          share|improve this answer












          You could refer to the below code:



          Function RangetoHTMLFlexWidth(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") & "" & Format(Now, "dd-mm-yy h-mm-ss") & ".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)
          RangetoHTMLFlexWidth = ts.readall
          ts.Close
          RangetoHTMLFlexWidth = Replace(RangetoHTMLFlexWidth, "align=center x:publishsource=", _
          "align=left x:publishsource=")

          Dim startIndex As Long
          Dim stopIndex As Long
          Dim subString As String

          'Change table width to "100%"
          startIndex = InStr(RangetoHTMLFlexWidth, "<table")
          startIndex = InStr(startIndex, RangetoHTMLFlexWidth, "width:") + 5
          stopIndex = InStr(startIndex, RangetoHTMLFlexWidth, "'>")
          subString = Left(RangetoHTMLFlexWidth, startIndex)
          subString = subString & "100%"
          RangetoHTMLFlexWidth = subString & Mid(RangetoHTMLFlexWidth, stopIndex)

          '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


          For more information, please refer to the below link:



          Send Excel range into Email body with autofit







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 '18 at 5:14









          Alina Li

          621125




          621125












          • Thank you, this works fine. But there is trouble with sending Graphs, they are not included in the selection.
            – KAdman
            Nov 20 '18 at 14:41












          • Maybe this link will help for you:stackoverflow.com/questions/27042842/…
            – Alina Li
            Nov 21 '18 at 9:26










          • Well, ok in case I will resign to the sending the whole thing (Range A1:X600) as a picture. This code would work, but the image disturbe the text in the graphs and bold text in tables so it is unreadable. Realy the best way would be to just use the MailEnvelope attitude, but with some condition that it will keep the positions of graphs and the hight of rows.
            – KAdman
            Nov 23 '18 at 9:20


















          • Thank you, this works fine. But there is trouble with sending Graphs, they are not included in the selection.
            – KAdman
            Nov 20 '18 at 14:41












          • Maybe this link will help for you:stackoverflow.com/questions/27042842/…
            – Alina Li
            Nov 21 '18 at 9:26










          • Well, ok in case I will resign to the sending the whole thing (Range A1:X600) as a picture. This code would work, but the image disturbe the text in the graphs and bold text in tables so it is unreadable. Realy the best way would be to just use the MailEnvelope attitude, but with some condition that it will keep the positions of graphs and the hight of rows.
            – KAdman
            Nov 23 '18 at 9:20
















          Thank you, this works fine. But there is trouble with sending Graphs, they are not included in the selection.
          – KAdman
          Nov 20 '18 at 14:41






          Thank you, this works fine. But there is trouble with sending Graphs, they are not included in the selection.
          – KAdman
          Nov 20 '18 at 14:41














          Maybe this link will help for you:stackoverflow.com/questions/27042842/…
          – Alina Li
          Nov 21 '18 at 9:26




          Maybe this link will help for you:stackoverflow.com/questions/27042842/…
          – Alina Li
          Nov 21 '18 at 9:26












          Well, ok in case I will resign to the sending the whole thing (Range A1:X600) as a picture. This code would work, but the image disturbe the text in the graphs and bold text in tables so it is unreadable. Realy the best way would be to just use the MailEnvelope attitude, but with some condition that it will keep the positions of graphs and the hight of rows.
          – KAdman
          Nov 23 '18 at 9:20




          Well, ok in case I will resign to the sending the whole thing (Range A1:X600) as a picture. This code would work, but the image disturbe the text in the graphs and bold text in tables so it is unreadable. Realy the best way would be to just use the MailEnvelope attitude, but with some condition that it will keep the positions of graphs and the hight of rows.
          – KAdman
          Nov 23 '18 at 9:20


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374822%2fexcel-selected-range-to-outlook-email-body-formatting-problem%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith