Copy from Excel to Outlook - white cells behind topleft corner of image












0















I am copying excel content from Excel to the Outlook Email Body, and unlike many other users my problem is not that cell formatting is messed up, but rather that when copying any of the images from excel, they are pasted into outlook with a white cell behind the image's top left corner.



Attached a sample image with how it looks in Excel and then in Outlook.



enter image description here



I have spent hours trying to solve this including:




  • change the format of the image (PNG/JPG/BMP)

  • play around with resolution, image compression, move-and-size-with-cells option, etc.

  • tried to manually copy the range into the outlook email body VS copying it via a macro which converts the worksheet-range into a html string and generates the email directly from excel


The last option, where I used VBA to generate the email from excel directly, exhibits the exact some problem as a manual copy & paste from excel. The problem only occurs around the area of images and the cells that are touched by the topleft corner of the image, no matter if those cells are regular cells or merged.



This leads me to believe that this is either an issue with my images/object (I replaced all images with shapes and had the same issue, or its bug in MS Office in when it comes to handling the copy & paste process of content with objects.



Would love to hear some opinions of you guys, I am at the end of my wit.



Thank you!



Also, here the function I use for copying the range to outlook.



Excel VBA



Option Explicit

Private Function RngToEmail(rng As Range, eTo As String, eSubject As String)
Dim wbThis As Workbook, wbNew As Workbook
Dim tempFileName As String, imgName As String, newPath As String

'~~> Do not change "Myimg". This will be used to
'~~> identify the images
Dim imgPrefix As String: imgPrefix = "Myimg"

'~~> This is the temp html file name.
'~~> Do not change this as when you publish the
'~~> html file, it will create a folder Temp_files
'~~> to store the images
Dim tmpFile As String: tmpFile = "Temp.Htm"

Set wbThis = Workbooks(rng.Parent.Parent.Name)
Set wbNew = Workbooks.Add

'~~> Copy the relevant range to new workbook
rng.Copy wbNew.Worksheets("Sheet1").Range("A:A")

newPath = wbThis.Path & ""
tempFileName = newPath & tmpFile

'~~> Publish the image
With wbNew.PublishObjects.Add(xlSourceRange, _
tempFileName, "Sheet1", rng.Address, xlHtmlStatic, _
imgPrefix, "")
.Publish (True)
.AutoRepublish = True
End With

'~~> Close the new file without saving
wbNew.Close (False)

'~~> Read the html file in a string in one go
Dim MyData As String, strData() As String
Dim i As Long
Open tempFileName For Binary As #1
MyData = Space$(LOF(1))
Get #1, , MyData
Close #1
strData() = Split(MyData, vbCrLf)

'~~> Loop through the file
For i = LBound(strData) To UBound(strData)
'~~> Here we will first get the image names
If InStr(1, strData(i), "Myimg_", vbTextCompare) And InStr(1, strData(i), ".Png", vbTextCompare) Then
'~~> Insert actual path to the images
strData(i) = Replace(strData(i), "Temp_files/", newPath & "Temp_files")
End If
Next i

'~~> Rejoin to get the new html string
MyData = Join(strData, vbCrLf)

'~~> Create the Email
Dim OutApp As Object, OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

With OutMail
.to = eTo
.Subject = eSubject

'~~> Set the body
.HTMLBody = MyData

'~~> Show the email. Change it to `.Send` to send it
.Display
End With

'~~> Delete the temp file name
Kill tempFileName
End Function

Sub Sample()
RngToEmail ThisWorkbook.Sheets("FINAL").Range("A:F"), "someemail@someserver.com", "Some Subject"
End Sub









share|improve this question





























    0















    I am copying excel content from Excel to the Outlook Email Body, and unlike many other users my problem is not that cell formatting is messed up, but rather that when copying any of the images from excel, they are pasted into outlook with a white cell behind the image's top left corner.



    Attached a sample image with how it looks in Excel and then in Outlook.



    enter image description here



    I have spent hours trying to solve this including:




    • change the format of the image (PNG/JPG/BMP)

    • play around with resolution, image compression, move-and-size-with-cells option, etc.

    • tried to manually copy the range into the outlook email body VS copying it via a macro which converts the worksheet-range into a html string and generates the email directly from excel


    The last option, where I used VBA to generate the email from excel directly, exhibits the exact some problem as a manual copy & paste from excel. The problem only occurs around the area of images and the cells that are touched by the topleft corner of the image, no matter if those cells are regular cells or merged.



    This leads me to believe that this is either an issue with my images/object (I replaced all images with shapes and had the same issue, or its bug in MS Office in when it comes to handling the copy & paste process of content with objects.



    Would love to hear some opinions of you guys, I am at the end of my wit.



    Thank you!



    Also, here the function I use for copying the range to outlook.



    Excel VBA



    Option Explicit

    Private Function RngToEmail(rng As Range, eTo As String, eSubject As String)
    Dim wbThis As Workbook, wbNew As Workbook
    Dim tempFileName As String, imgName As String, newPath As String

    '~~> Do not change "Myimg". This will be used to
    '~~> identify the images
    Dim imgPrefix As String: imgPrefix = "Myimg"

    '~~> This is the temp html file name.
    '~~> Do not change this as when you publish the
    '~~> html file, it will create a folder Temp_files
    '~~> to store the images
    Dim tmpFile As String: tmpFile = "Temp.Htm"

    Set wbThis = Workbooks(rng.Parent.Parent.Name)
    Set wbNew = Workbooks.Add

    '~~> Copy the relevant range to new workbook
    rng.Copy wbNew.Worksheets("Sheet1").Range("A:A")

    newPath = wbThis.Path & ""
    tempFileName = newPath & tmpFile

    '~~> Publish the image
    With wbNew.PublishObjects.Add(xlSourceRange, _
    tempFileName, "Sheet1", rng.Address, xlHtmlStatic, _
    imgPrefix, "")
    .Publish (True)
    .AutoRepublish = True
    End With

    '~~> Close the new file without saving
    wbNew.Close (False)

    '~~> Read the html file in a string in one go
    Dim MyData As String, strData() As String
    Dim i As Long
    Open tempFileName For Binary As #1
    MyData = Space$(LOF(1))
    Get #1, , MyData
    Close #1
    strData() = Split(MyData, vbCrLf)

    '~~> Loop through the file
    For i = LBound(strData) To UBound(strData)
    '~~> Here we will first get the image names
    If InStr(1, strData(i), "Myimg_", vbTextCompare) And InStr(1, strData(i), ".Png", vbTextCompare) Then
    '~~> Insert actual path to the images
    strData(i) = Replace(strData(i), "Temp_files/", newPath & "Temp_files")
    End If
    Next i

    '~~> Rejoin to get the new html string
    MyData = Join(strData, vbCrLf)

    '~~> Create the Email
    Dim OutApp As Object, OutMail As Object
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    With OutMail
    .to = eTo
    .Subject = eSubject

    '~~> Set the body
    .HTMLBody = MyData

    '~~> Show the email. Change it to `.Send` to send it
    .Display
    End With

    '~~> Delete the temp file name
    Kill tempFileName
    End Function

    Sub Sample()
    RngToEmail ThisWorkbook.Sheets("FINAL").Range("A:F"), "someemail@someserver.com", "Some Subject"
    End Sub









    share|improve this question



























      0












      0








      0








      I am copying excel content from Excel to the Outlook Email Body, and unlike many other users my problem is not that cell formatting is messed up, but rather that when copying any of the images from excel, they are pasted into outlook with a white cell behind the image's top left corner.



      Attached a sample image with how it looks in Excel and then in Outlook.



      enter image description here



      I have spent hours trying to solve this including:




      • change the format of the image (PNG/JPG/BMP)

      • play around with resolution, image compression, move-and-size-with-cells option, etc.

      • tried to manually copy the range into the outlook email body VS copying it via a macro which converts the worksheet-range into a html string and generates the email directly from excel


      The last option, where I used VBA to generate the email from excel directly, exhibits the exact some problem as a manual copy & paste from excel. The problem only occurs around the area of images and the cells that are touched by the topleft corner of the image, no matter if those cells are regular cells or merged.



      This leads me to believe that this is either an issue with my images/object (I replaced all images with shapes and had the same issue, or its bug in MS Office in when it comes to handling the copy & paste process of content with objects.



      Would love to hear some opinions of you guys, I am at the end of my wit.



      Thank you!



      Also, here the function I use for copying the range to outlook.



      Excel VBA



      Option Explicit

      Private Function RngToEmail(rng As Range, eTo As String, eSubject As String)
      Dim wbThis As Workbook, wbNew As Workbook
      Dim tempFileName As String, imgName As String, newPath As String

      '~~> Do not change "Myimg". This will be used to
      '~~> identify the images
      Dim imgPrefix As String: imgPrefix = "Myimg"

      '~~> This is the temp html file name.
      '~~> Do not change this as when you publish the
      '~~> html file, it will create a folder Temp_files
      '~~> to store the images
      Dim tmpFile As String: tmpFile = "Temp.Htm"

      Set wbThis = Workbooks(rng.Parent.Parent.Name)
      Set wbNew = Workbooks.Add

      '~~> Copy the relevant range to new workbook
      rng.Copy wbNew.Worksheets("Sheet1").Range("A:A")

      newPath = wbThis.Path & ""
      tempFileName = newPath & tmpFile

      '~~> Publish the image
      With wbNew.PublishObjects.Add(xlSourceRange, _
      tempFileName, "Sheet1", rng.Address, xlHtmlStatic, _
      imgPrefix, "")
      .Publish (True)
      .AutoRepublish = True
      End With

      '~~> Close the new file without saving
      wbNew.Close (False)

      '~~> Read the html file in a string in one go
      Dim MyData As String, strData() As String
      Dim i As Long
      Open tempFileName For Binary As #1
      MyData = Space$(LOF(1))
      Get #1, , MyData
      Close #1
      strData() = Split(MyData, vbCrLf)

      '~~> Loop through the file
      For i = LBound(strData) To UBound(strData)
      '~~> Here we will first get the image names
      If InStr(1, strData(i), "Myimg_", vbTextCompare) And InStr(1, strData(i), ".Png", vbTextCompare) Then
      '~~> Insert actual path to the images
      strData(i) = Replace(strData(i), "Temp_files/", newPath & "Temp_files")
      End If
      Next i

      '~~> Rejoin to get the new html string
      MyData = Join(strData, vbCrLf)

      '~~> Create the Email
      Dim OutApp As Object, OutMail As Object
      Set OutApp = CreateObject("Outlook.Application")
      Set OutMail = OutApp.CreateItem(0)

      With OutMail
      .to = eTo
      .Subject = eSubject

      '~~> Set the body
      .HTMLBody = MyData

      '~~> Show the email. Change it to `.Send` to send it
      .Display
      End With

      '~~> Delete the temp file name
      Kill tempFileName
      End Function

      Sub Sample()
      RngToEmail ThisWorkbook.Sheets("FINAL").Range("A:F"), "someemail@someserver.com", "Some Subject"
      End Sub









      share|improve this question
















      I am copying excel content from Excel to the Outlook Email Body, and unlike many other users my problem is not that cell formatting is messed up, but rather that when copying any of the images from excel, they are pasted into outlook with a white cell behind the image's top left corner.



      Attached a sample image with how it looks in Excel and then in Outlook.



      enter image description here



      I have spent hours trying to solve this including:




      • change the format of the image (PNG/JPG/BMP)

      • play around with resolution, image compression, move-and-size-with-cells option, etc.

      • tried to manually copy the range into the outlook email body VS copying it via a macro which converts the worksheet-range into a html string and generates the email directly from excel


      The last option, where I used VBA to generate the email from excel directly, exhibits the exact some problem as a manual copy & paste from excel. The problem only occurs around the area of images and the cells that are touched by the topleft corner of the image, no matter if those cells are regular cells or merged.



      This leads me to believe that this is either an issue with my images/object (I replaced all images with shapes and had the same issue, or its bug in MS Office in when it comes to handling the copy & paste process of content with objects.



      Would love to hear some opinions of you guys, I am at the end of my wit.



      Thank you!



      Also, here the function I use for copying the range to outlook.



      Excel VBA



      Option Explicit

      Private Function RngToEmail(rng As Range, eTo As String, eSubject As String)
      Dim wbThis As Workbook, wbNew As Workbook
      Dim tempFileName As String, imgName As String, newPath As String

      '~~> Do not change "Myimg". This will be used to
      '~~> identify the images
      Dim imgPrefix As String: imgPrefix = "Myimg"

      '~~> This is the temp html file name.
      '~~> Do not change this as when you publish the
      '~~> html file, it will create a folder Temp_files
      '~~> to store the images
      Dim tmpFile As String: tmpFile = "Temp.Htm"

      Set wbThis = Workbooks(rng.Parent.Parent.Name)
      Set wbNew = Workbooks.Add

      '~~> Copy the relevant range to new workbook
      rng.Copy wbNew.Worksheets("Sheet1").Range("A:A")

      newPath = wbThis.Path & ""
      tempFileName = newPath & tmpFile

      '~~> Publish the image
      With wbNew.PublishObjects.Add(xlSourceRange, _
      tempFileName, "Sheet1", rng.Address, xlHtmlStatic, _
      imgPrefix, "")
      .Publish (True)
      .AutoRepublish = True
      End With

      '~~> Close the new file without saving
      wbNew.Close (False)

      '~~> Read the html file in a string in one go
      Dim MyData As String, strData() As String
      Dim i As Long
      Open tempFileName For Binary As #1
      MyData = Space$(LOF(1))
      Get #1, , MyData
      Close #1
      strData() = Split(MyData, vbCrLf)

      '~~> Loop through the file
      For i = LBound(strData) To UBound(strData)
      '~~> Here we will first get the image names
      If InStr(1, strData(i), "Myimg_", vbTextCompare) And InStr(1, strData(i), ".Png", vbTextCompare) Then
      '~~> Insert actual path to the images
      strData(i) = Replace(strData(i), "Temp_files/", newPath & "Temp_files")
      End If
      Next i

      '~~> Rejoin to get the new html string
      MyData = Join(strData, vbCrLf)

      '~~> Create the Email
      Dim OutApp As Object, OutMail As Object
      Set OutApp = CreateObject("Outlook.Application")
      Set OutMail = OutApp.CreateItem(0)

      With OutMail
      .to = eTo
      .Subject = eSubject

      '~~> Set the body
      .HTMLBody = MyData

      '~~> Show the email. Change it to `.Send` to send it
      .Display
      End With

      '~~> Delete the temp file name
      Kill tempFileName
      End Function

      Sub Sample()
      RngToEmail ThisWorkbook.Sheets("FINAL").Range("A:F"), "someemail@someserver.com", "Some Subject"
      End Sub






      microsoft-excel email microsoft-excel-2010 microsoft-outlook






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 7 at 11:15









      Ahmed Ashour

      1,3401715




      1,3401715










      asked Jan 7 at 9:32









      PatrickPatrick

      1




      1






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Do you insert picture to this cell? When testing on my Outlook 2016 version 1812, I also find the issue. The cell behind the picture would appear blank or wired when pasting to email body. I haven’t found related official articles and I’m not familiar with VBA code.



          enter image description here



          However, we can choose to paste as a picture in Paste Options to avoid this.



          enter image description here






          share|improve this answer
























          • Hmmm, I have the same issue but even when pasting as picture, the problem remains. Is this a bug in Excel?

            – Armitage2k
            Jan 15 at 10:17











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          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%2fsuperuser.com%2fquestions%2f1391418%2fcopy-from-excel-to-outlook-white-cells-behind-topleft-corner-of-image%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














          Do you insert picture to this cell? When testing on my Outlook 2016 version 1812, I also find the issue. The cell behind the picture would appear blank or wired when pasting to email body. I haven’t found related official articles and I’m not familiar with VBA code.



          enter image description here



          However, we can choose to paste as a picture in Paste Options to avoid this.



          enter image description here






          share|improve this answer
























          • Hmmm, I have the same issue but even when pasting as picture, the problem remains. Is this a bug in Excel?

            – Armitage2k
            Jan 15 at 10:17
















          0














          Do you insert picture to this cell? When testing on my Outlook 2016 version 1812, I also find the issue. The cell behind the picture would appear blank or wired when pasting to email body. I haven’t found related official articles and I’m not familiar with VBA code.



          enter image description here



          However, we can choose to paste as a picture in Paste Options to avoid this.



          enter image description here






          share|improve this answer
























          • Hmmm, I have the same issue but even when pasting as picture, the problem remains. Is this a bug in Excel?

            – Armitage2k
            Jan 15 at 10:17














          0












          0








          0







          Do you insert picture to this cell? When testing on my Outlook 2016 version 1812, I also find the issue. The cell behind the picture would appear blank or wired when pasting to email body. I haven’t found related official articles and I’m not familiar with VBA code.



          enter image description here



          However, we can choose to paste as a picture in Paste Options to avoid this.



          enter image description here






          share|improve this answer













          Do you insert picture to this cell? When testing on my Outlook 2016 version 1812, I also find the issue. The cell behind the picture would appear blank or wired when pasting to email body. I haven’t found related official articles and I’m not familiar with VBA code.



          enter image description here



          However, we can choose to paste as a picture in Paste Options to avoid this.



          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 8 at 5:29









          PerryPerry

          1163




          1163













          • Hmmm, I have the same issue but even when pasting as picture, the problem remains. Is this a bug in Excel?

            – Armitage2k
            Jan 15 at 10:17



















          • Hmmm, I have the same issue but even when pasting as picture, the problem remains. Is this a bug in Excel?

            – Armitage2k
            Jan 15 at 10:17

















          Hmmm, I have the same issue but even when pasting as picture, the problem remains. Is this a bug in Excel?

          – Armitage2k
          Jan 15 at 10:17





          Hmmm, I have the same issue but even when pasting as picture, the problem remains. Is this a bug in Excel?

          – Armitage2k
          Jan 15 at 10:17


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • 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%2fsuperuser.com%2fquestions%2f1391418%2fcopy-from-excel-to-outlook-white-cells-behind-topleft-corner-of-image%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

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          RAC Tourist Trophy