Consulting

Results 1 to 4 of 4

Thread: Reply email with extra text in Body

  1. #1

    Reply email with extra text in Body

    Hi

    I fount code to repy email with HTML body. thats fine. And now please help me how can I add some text on the top of replying email. Text will me static ( no change)

    in other world .

    Need to reply email with question : "Any Reply?"

    Sub ForceReplyInHTML()
        ' Description: Outlook macro to reply to a message in HTML
        ' regardless of the current message format.
        ' The reply will use your HTML signature as well.
        ' author : Robert Sparnaaij
        ' version: 1.0
        Dim objOL As Outlook.Application
        Dim objSelection As Outlook.Selection
        Dim objItem As Object
        Set objOL = Outlook.Application
        ' Get the selected item
        Select Case TypeName(objOL.ActiveWindow)
            Case "Explorer"
                Set objSelection = objOL.ActiveExplorer.Selection
                If objSelection.Count > 0 Then
                    Set objItem = objSelection.Item(1)
                Else
                    Result = MsgBox("No item selected. " & _
                    "Please make a selection first.", _
                    vbCritical, "Reply in HTML")
                    Exit Sub
                End If
            Case "Inspector"
                Set objItem = objOL.ActiveInspector.CurrentItem
            Case Else
                Result = MsgBox("Unsupported Window type." & _
                vbNewLine & "Please make a selection" & _
                " or open an item first.", _
                vbCritical, "Reply in HTML")
                Exit Sub
        End Select
        Dim olMsg As Outlook.MailItem
        Dim olMsgReply As Outlook.MailItem
        Dim IsPlainText As Boolean
        ' Change the message format and reply
        If objItem.Class = olMail Then
            Set olMsg = objItem
            If olMsg.BodyFormat = olFormatPlain Then
                IsPlainText = True
            End If
            olMsg.BodyFormat = olFormatHTML
            Set olMsgReply = olMsg.Reply
            If IsPlainText = True Then
                olMsg.BodyFormat = olFormatPlain
            End If
            olMsg.Close (olSave)
            olMsgReply.Display
            ' Selected item isn't a mail item
        Else
            Result = MsgBox("No message item selected. " & _
            "Please make a selection first.", _
            vbCritical, "Reply in HTML")
            Exit Sub
        End If
        ' Cleanup
        Set objOL = Nothing
        Set objItem = Nothing
        Set objSelection = Nothing
       Set olMsg = Nothing
        Set olMsgReply = Nothing
    End Sub
    Last edited by Aussiebear; 01-25-2025 at 11:39 PM.

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    Try this:

    olMsg.BodyFormat = olFormatHTML
    Set olMsgReply = olMsg.Reply
    olMsgReply.HTMLBody = "Any Reply?" & olMsgReply.HTMLBody
    Last edited by Aussiebear; 01-25-2025 at 11:31 PM.
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  3. #3
    I did put that cod here :

    ' Change the message format and reply
    If objItem.Class = olMail Then
        Set olMsg = objItem
        If olMsg.BodyFormat = olFormatPlain Then
            IsPlainText = True
        End If
        olMsg.BodyFormat = olFormatHTML
        Set olMsgReply = olMsg.Reply
        If IsPlainText = True Then
            olMsgReply.HTMLBody = "Any Reply?" & olMsgReply.HTMLBody
        End If
        olMsg.Close (olSave)
        olMsgReply.Display
    and is not working
    Last edited by Aussiebear; 01-25-2025 at 11:32 PM.

  4. #4
    Let's start again with the whole macro and remove some of the superfluous code:
    Option Explicit
    
    Sub ForceReplyInHTML()
        ' Description: Outlook macro to reply to a message in HTML
        ' regardless of the current message format.
        ' The reply will use your HTML signature as well.
        ' author : Robert Sparnaaij modified by Graham Mayor
        ' version: 1.1
        Dim objOL As Outlook.Application
        Dim objSelection As Outlook.Selection
        Dim objItem As Object
        Dim olMsg As Outlook.MailItem
        Dim olMsgReply As Outlook.MailItem
        Dim IsPlainText As Boolean
        Set objOL = Outlook.Application
        ' Get the selected item
        Select Case TypeName(objOL.ActiveWindow)
            Case "Explorer"
                Set objSelection = objOL.ActiveExplorer.Selection
                If objSelection.Count > 0 Then
                    Set objItem = objSelection.Item(1)
                Else
                    MsgBox "No item selected. " & _
                                    "Please make a selection first.", _
                                    vbCritical, "Reply in HTML"
                    Exit Sub
                End If
            Case "Inspector"
                Set objItem = objOL.ActiveInspector.CurrentItem
            Case Else
               MsgBox "Unsupported Window type." & _
                                vbNewLine & "Please make a selection" & _
                                " or open an item first.", _
                                vbCritical, "Reply in HTML"
                Exit Sub
        End Select
        'Change the message format and reply
        If objItem.Class = olMail Then
            'Set olMsg = objItem
            If objItem.BodyFormat = olFormatPlain Then
                IsPlainText = True
            End If
            objItem.BodyFormat = olFormatHTML
            Set olMsgReply = objItem.Reply
            If IsPlainText = True Then
                objItem.BodyFormat = olFormatPlain
            End If
            objItem.Close 1
            olMsgReply.BodyFormat = olFormatHTML
            olMsgReply.Display
            olMsgReply.HTMLBody = "Any Reply?" & olMsgReply.HTMLBody
            'Selected item isn't a mail item
        Else
            MsgBox "No message item selected. " & _
                            "Please make a selection first.", _
                            vbCritical, "Reply in HTML"
        End If
        'Cleanup
        Set objOL = Nothing
        Set objItem = Nothing
        Set objSelection = Nothing
        'Set olMsg = Nothing
        Set olMsgReply = Nothing
    End Sub
    Last edited by Aussiebear; 01-25-2025 at 11:33 PM.
    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
  •