Solved

Outlook 2010, VBA and Tab question

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
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…

690 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