none
Creating one cell table and embedding a document RRS feed

  • Question

  • Hi:

    I am VBA coding within Excel to create an email.  In this email, I want a border around a certain part of the text that has a file embedded into the table cell/email (do not want the file displayed, rather attached).  When the email was just text, I used a "strBody" and then a HTMLBody function and it worked great.  Now that I need to create a one cell table and a file attached within that table, I am at a loss of how to do that.  Would appreciate directing me in the right direction.  Thank you.  (I am attaching how I need it to look and after the ***** line, is the code I had that worked for straight text.

    Good Day,
    
    This is test email.
    
    (this is where the one cell table goes ...
    This is one table cell with context here.
    
    Embedded-document.xls)
    
    Best regards,
    Me
    *****************************************************
    
    strBody = "Good day:<br><br>" & _
                 "This is a test email. "
    
    SigString = Environ("appdata") & _
                    "\Microsoft\Signatures\me.htm"
    
        If Dir(SigString) <> "" Then
            Signature = GetBoiler(SigString)
        Else
            Signature = ""
        End If
        
           
        With Outmail
            .To = "me@canada.ca"
            .Subject = "Subject goes here”
            .HTMLBody = "<p style='color:#000000;font-family:Arial;font-size:17.5'>" & strBody & "</font>
            Call .Display
            Call .Recipients.resolveall
       End With
    End Sub
    

    Sunday, March 12, 2017 3:32 PM

Answers

  • Hello,

    You could use HTMLBody like:

    .HTMLBody = "<table border=1 cellspacing=0 " & _
    "cellpadding=0 style='border-collapse:collapse;border:none;" & _
    "" & _
    "<tr style='" & _
    "<td width=623 valign=top " & _
    "style='width:467.5pt;border:solid windowtext 1.0pt;" & _
    "solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt'><p>&nbsp;</p></td></tr></table>"
    .Display
    
    

    We add a table using <table> tag. Please visit https://www.w3schools.com/tags/tag_table.asp

    For the embedded file, please visit Attachments.Add Method (Outlook): Position parameter applies only to e-mail messages using the Rich Text format. So if you want to embed file in the body, we need to change its format into Rich Text format, then we are unable to edit body using HTMLBody.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by WandaM Wednesday, March 15, 2017 3:54 PM
    Monday, March 13, 2017 8:15 AM
    Moderator
  • Thank you for the response.  The table cell worked.  I am still working on the attachment to put in the table, but I know I am close to success.  Thank you once again.  Very much appreciated.
    • Marked as answer by WandaM Tuesday, March 14, 2017 2:08 AM
    Tuesday, March 14, 2017 2:08 AM
  • Hi,

    >>are you saying that unless the entire email is coded for rich text you can't add an attachment through code?

    No. If the mail body is Rich Text format, we could specify the location of the attachment using Position parameter.

    If it is HTML format, the attachment would be added into Attached field.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by WandaM Wednesday, March 15, 2017 3:54 PM
    Wednesday, March 15, 2017 8:56 AM
    Moderator

All replies

  • Hello,

    You could use HTMLBody like:

    .HTMLBody = "<table border=1 cellspacing=0 " & _
    "cellpadding=0 style='border-collapse:collapse;border:none;" & _
    "" & _
    "<tr style='" & _
    "<td width=623 valign=top " & _
    "style='width:467.5pt;border:solid windowtext 1.0pt;" & _
    "solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt'><p>&nbsp;</p></td></tr></table>"
    .Display
    
    

    We add a table using <table> tag. Please visit https://www.w3schools.com/tags/tag_table.asp

    For the embedded file, please visit Attachments.Add Method (Outlook): Position parameter applies only to e-mail messages using the Rich Text format. So if you want to embed file in the body, we need to change its format into Rich Text format, then we are unable to edit body using HTMLBody.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by WandaM Wednesday, March 15, 2017 3:54 PM
    Monday, March 13, 2017 8:15 AM
    Moderator
  • Thank you for the response.  The table cell worked.  I am still working on the attachment to put in the table, but I know I am close to success.  Thank you once again.  Very much appreciated.
    • Marked as answer by WandaM Tuesday, March 14, 2017 2:08 AM
    Tuesday, March 14, 2017 2:08 AM
  • Hi Celeste:

    I was able to create the table with 2 columns and 5 rows, which works great.  I looked at the Attachments.Add Method.  I want to make sure I have you correct, before making a decision of adding the attachment manually .... are you saying that unless the entire email is coded for rich text you can't add an attachment through code?  Thank you.

    Tuesday, March 14, 2017 10:26 PM
  • Hi,

    >>are you saying that unless the entire email is coded for rich text you can't add an attachment through code?

    No. If the mail body is Rich Text format, we could specify the location of the attachment using Position parameter.

    If it is HTML format, the attachment would be added into Attached field.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by WandaM Wednesday, March 15, 2017 3:54 PM
    Wednesday, March 15, 2017 8:56 AM
    Moderator
  • Totally understand now.  Tried it and it works perfect.  Thank you.
    Wednesday, March 15, 2017 3:54 PM