Solved

Outlook 2010, VBA and Tab question

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

803 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