Solved

Outlook 2010, VBA and Tab question

Posted on 2016-10-28
4
49 Views
Last Modified: 2016-11-02
in Excel VBA I am building up the Body of an email I'm sending in Outlook 2010.

This is my code snippet.

        strbody = "Hi there" & vbNewLine & vbNewLine & _
              "This is line 1" & vbTab & "Email1" & vbTab & "Notes 1" & vbNewLine & _
              "This is line 2" & vbTab & "Email2" & vbTab & "Notes 2" & vbNewLine & _
              "This is line 3" & vbTab & "Email3" & vbTab & "Notes 3" & vbNewLine & _
              "This is line 4" & vbTab & "Email4" & vbTab & "Notes 4"

Open in new window


Now the first column 'This is line 1' could be of variable length. So the Email 1 etc may not line up properly vertically.
Similarly for the Notes column.

Is there an easy way of making the columns line up?

Or, how do I know what the width of the tab is? So that I can work out the length of the string and code the adjustment? (ie. whether I need 1 or 2 tabs to fill the gap)
0
Comment
Question by:hindersaliva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 41865098
I would consider setting the mail format to be HTML, then use a html table to align your data.
almost all current email readers understand html formatted messages.

not modern but it works all the time....  you can set min-width on columns and they should autoexpand to the windows size as necessary
0
 

Author Comment

by:hindersaliva
ID: 41865113
Yes Robr, I though so too. Can you recommend a link to some know-how on it please?
0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
ID: 41865120
just set body to be html

strBody = "<html><body>"
strbody = strBody & "<h1>Hi There</h1>"
strbody = strBody & "<table style='width:100%'>"
strbody = strBody & "<tr>"
strbody = strBody & "  <th>" & "this is line 1" & "</th>"
strbody = strBody & "  <th>" & "email1" & "</th>"
strbody = strBody & "  <th>" & "notes1" & "</th>"
strbody = strBody & "</tr>"
strbody = strBody & "<tr>"
strbody = strBody & "  <td>" & "this is line 2" & "</td>"
strbody = strBody & "  <td>" & "email2" & "</td>"
strbody = strBody & "  <td>" & "notes2" & "</td>"
strbody = strBody & "</tr>"
strbody = strBody & "</table>"
strbody = strBody & "</body>"
strbody = strBody & "</html>"

      msg.BodyFormat = olFormatHTML
      msg.HTMLBody = strBody

Open in new window


https://msdn.microsoft.com/en-us/library/office/aa171418(v=office.11).aspx

http://www.w3schools.com/html/html_tables.asp
0
 

Author Comment

by:hindersaliva
ID: 41865136
Hey thanks robr!
That will do me nicely!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question