?
Solved

Outlook 2010, VBA and Tab question

Posted on 2016-10-28
4
Medium Priority
?
56 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 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

800 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