Results 1 to 10 of 10
  1. #1
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    Outlook email - format, line spacing

    I have the below snippet of code to create an Outlook Email.


    ...No issues, it does what it ought to do, with one exception:
    Although the code calls for 0 spaces before or after a paragraph, the result is the spacing is set to AUTO (which in this office results in a space after every line.)
    -not even certain if this is a code thing -or-an Outlook thing...

    any thoughts will be greatly appreciated in advance,
    m.

    Code:
    Public Sub SendEmail(varaddress As Variant, varsubject As String, varbody As String)
        On Error Resume Next
        Dim olApp As Object
        Dim objMail As Object
        Set olApp = CreateObject("Outlook.Application")    'Create a new instance of Outlook
        'Create e-mail item
        Set objMail = olApp.CreateItem(0)
        With objMail
            'Set body format to HTML
            '        .bodyformat = 2
    
            Dim vTitle As String
            Dim vPrompt As String
            Dim Responce As Variant
            If IsNull(varaddress) Then
                vTitle = "MISSING ADDRESS"
                vPrompt = "Address is incorrect or missing; no email will be sent"
                Responce = MsgBox(vPrompt, vbOKOnly + vbCritical, vTitle)
                Exit Sub
            Else
                With objMail
                    .To = varaddress & ""
                    .Subject = Nz(varsubject, "")
                    .HTMLBody = "<span style='font:calibri, font-size:11pt, Paragraph.SpaceAfter = 0, Paragraph.SpaceBefore = 0;'>" & Nz(varbody, "") & Format(Now) & "<\span>"
                    .Body = Nz(varbody, "")
                    .Save
                    .Display
                End With
            End If
        End With
        Set olApp = Nothing
        Set objMail = Nothing
    
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Use <br> tag to add lines in HTML formatted text.

    I can't find any info on Paragraph other than <p> tag.

    It could be an on/off toggle, not specifying a number of lines. If you don't want line space, try without.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Does varBody value contain line breaking characters?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    yes, it does (always)

    interesting just notice...
    if i comment out the line:
    Code:
    '      .Body = Nz(varbody, "")
    of course the email has no text in its body, but the paragraph line spacing is not screwed up

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Sorry, didn't notice you had both.

    I think .Body and .HTMLBody conflict.

    IIRC, HTMLBody ignores CrLf characters.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Good catch - but the issue is that there are extra lines? So I was wondering if varbody contains them. As for the body vs htmlbody thing, should be
    .HTMLBody = "<span style= ..."<\span>" & varbody ?
    Not seeing the need for Nz there.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    True, explicitly declared variable can never be Null unless it is Variant. Attempt to pass Null will result in run-time error.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    to clarify, there's not extra lines; there's extra space.
    this is not a problem with the text added by code (varBody); it is a problem when the user continues to type within the email (which, almost without exception happens.) The spacing in varBody is as defined in the code.

    the Before and After paragraph Spacing defaults to 'AUTO', which adds unwanted points space before and after each paragraph (effectively... each line -since clicking enter at the end of a sentence to move to a new line defines a 'paragraph')

    what i need to do is to set: Paragraph / Indents and Spacing / Spacing / Before and After to be '0 pt' (not 'auto'); which i had hoped the code would be doing, but it is not

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    I cannot replicate issue. I type in my email and do not get extra spacing.

    What is the paragraph spacing setting on the ribbon?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    0 pt, 0 pt

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Line spacing
    By Alex Motilal in forum Reports
    Replies: 4
    Last Post: 04-06-2019, 05:45 PM
  2. adding current user to CC line of outlook email
    By billybeer in forum Programming
    Replies: 2
    Last Post: 12-13-2017, 10:45 AM
  3. Line feed for use in MS Outlook email
    By aytee111 in forum Programming
    Replies: 10
    Last Post: 10-21-2016, 12:50 PM
  4. Replies: 7
    Last Post: 11-19-2013, 01:58 PM
  5. line spacing in access 2010
    By Alexander Pooh in forum Access
    Replies: 5
    Last Post: 08-15-2012, 08:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums