Solved

Outlook 2010, VBA and Tab question

Posted on 2016-10-28
4
42 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now