Results 1 to 4 of 4

Thread: VBA Email Font

  1. #1
    Hyperactive Member
    Join Date
    Jun 06
    Location
    Best Place on Earth
    Posts
    363

    Question VBA Email Font

    I am using the following in a number of Excel VBA macros to send out Emails.

    VB Code:
    1. Sub SendMail(ByVal ToNames As String, ByVal CCNames As String,_
    2.                                 ByVal vSubject As String, ByVal vMessage As String, _
    3.                                 ByVal AttachFile As String)
    4. Dim OutApp As Object
    5. Dim OutMail As Object
    6. Const olMailItem = 0
    7. ' Sends out an Email with vMessage as the body and with the Subject as vSubject
    8. ' Sent to ToNames and CCNames, ToNames must not be blank
    9.     If ToNames = "" Then
    10.         Exit Sub
    11.     End If
    12.     Set OutApp = CreateObject("Outlook.Application")
    13.     Set OutMail = OutApp.CreateItem(olMailItem)
    14.     With OutMail
    15.         .To = ToNames
    16.         .cc = CCNames
    17.         .Subject = vSubject
    18.         .Body = vMessage & vbCr & vbCr
    19.         If AttachFile <> "" Then
    20.             .Attachments.Add AttachFile
    21.         End If
    22.         .Send
    23.     End With
    24.     Set OutMail = Nothing
    25.     Set OutApp = Nothing
    26. End Sub

    The code works perfectly, however I now need to send out an email with
    data on it in the form of a table

    The data is in the form of a String, and two Long's.

    I would like to present it neatly, but as the font is proportional I am getting
    the following results

    i.e.
    string1 9 8
    string2 10 12
    pas 8 1

    Can anyone offer any suggestions as to how I can embed a commend in my
    message string to use a Fixed Width font, or offer any suggestions as to how
    to display a neat looking table.
    Signature Under Construction

  2. #2
    Addicted Member
    Join Date
    Jan 02
    Location
    Glasgow, Scotland
    Posts
    202

    Re: VBA Email Font

    if i need to have a table in an e-mail i use Word as the e-mail container.

    not tried it with code as i use the SMTP dll just for normal e-mails with attachments, but couldnt you declare word instead of outlook and create your content this way?
    if you fail to plan, you plan to fail

  3. #3
    Hyperactive Member
    Join Date
    Jun 06
    Location
    Best Place on Earth
    Posts
    363

    Re: VBA Email Font

    I am building the messages up in an Excel macro.

    After a fairly heavy bit of processing I end up with the results, at present I just build
    these up in a string, which I then use the code above to send via EMail.

    I do not want to send the results as an attachment as that would significantly
    increase the size of the email.

    I think that it might be possible to change the font using tags of some sort, HTML?,
    but I have no experience with them.
    Signature Under Construction

  4. #4
    Addicted Member
    Join Date
    Jan 02
    Location
    Glasgow, Scotland
    Posts
    202

    Re: VBA Email Font

    i didnt mean as a word attachment though.

    if you go into word and select New>E-mail message

    word is used as your e-mail program and you can insert tables.

    i just wasnt sure if the sendmail dll would work with word in this way
    if you fail to plan, you plan to fail

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •