Consulting

Results 1 to 2 of 2

Thread: outlook vba

  1. #1
    VBAX Newbie
    Joined
    Dec 2018
    Posts
    4
    Location

    outlook vba

    I have outlook 2010,and I have signature assigned to rediffmail and gmail account.
    But when I create message using vba plaintext signature does not generate in message unless I keep open outlook before I run that code.
    And another thing is that if I choose richtext format for composing message in outlook options it works fine for plaintext and html and rich text.
    Is there any solution without keeping open outlook before running code.
    Pleaseeeee.... Help

  2. #2
    If you are using Outlook functionality then Outlook needs to be open while it is in use. The following will open outlook and create the message, retaining the signature.
    Note the comment at the top of the macro re required code

    Sub Send_As_Plain_EMail()'Graham Mayor - http://www.gmayor.com - Last updated - 14 Jul 2017
    'Requires the code from http://www.rondebruin.nl/win/s1/outlook/openclose.htm
    'to either retrieve an open instance of Outlook or open Outlook if it is closed.
    Dim bStarted As Boolean
    Dim olApp As Object
    Dim oItem As Object
    Dim objDoc As Object
    Dim strRecipient As String
    Dim strSubject As String
    Dim oRng As Object
    
    
        strRecipient = "someone@somewhere.com"
        strSubject = "This is the message subject"
        ActiveDocument.Range.Copy
        Set olApp = OutlookApp()
                Set oItem = olApp.CreateItem(0)
                With oItem
                    .BodyFormat = 1 'Plain text (2 for html)
                    .Display 'This line is required
                    Set objDoc = .GetInspector.WordEditor
                    Set oRng = objDoc.Range
                    oRng.Collapse 1
                    oRng.Text = "This is the message"
                    .To = strRecipient
                    .Subject = strSubject
                    '.Send 'Restore after testing
                End With
    lbl_Exit:
        Set oItem = Nothing
        Set olApp = Nothing
        Set objDoc = Nothing
        Set oRng = Nothing
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

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