Share via

Active Explorer vs Active Inspector Code

Anonymous
2023-11-22T21:36:27+00:00

The below macro works great with ActiveInspector but I don't know how to write the code for it to be compatible whether it is ActiveExplorer or ActiveInspector as sometimes I like to respond to emails in the folder view:

Sub ReplaceWithBoldHTML2()

Dim regExp As Object 

Set regExp = CreateObject("vbscript.regexp") 

Dim item As Object 

Set item = Application.ActiveInspector.CurrentItem 

If TypeOf item Is Outlook.mailItem Then 

    Dim bodyHTML As String 

    bodyHTML = item.htmlBody 

    ' Find the position of the signature 

    Dim signaturePos As Long 

    signaturePos = InStr(1, bodyHTML, "Best,") 

    ' Check if the signature is found 

    If signaturePos > 0 Then 

        ' Extract the portion of the body above the signature 

        Dim bodyAboveSignature As String 

        bodyAboveSignature = Left(bodyHTML, signaturePos - 1) 

        ' Apply the regex pattern to the extracted portion 

        With regExp 

            .pattern = "\$[0-9]{1,3}(([\.?,?][0-9]{1,3}){1,})?" 

            .Global = True 

            ' Iterate through each match in the HTML body above the signature 

            For Each match In .Execute(bodyAboveSignature) 

                ' Replace each match with a bold version 

                bodyAboveSignature = Replace(bodyAboveSignature, match.Value, "<b>" & match.Value & "</b>") 

            Next match 

        End With 

        ' Update the HTMLBody property with the modified HTML 

        item.htmlBody = bodyAboveSignature & Mid(bodyHTML, signaturePos) 

    Else 

        MsgBox "Signature not found.", vbExclamation 

    End If 

Else 

    MsgBox "This code is designed for MailItems in Outlook.", vbExclamation 

End If 

End Sub

Outlook | Windows | Classic Outlook for Windows | For home

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-11-22T23:31:54+00:00

    Dear Churchizactiive,

    Good day!

    Thank you for posting to Microsoft Community. We are glad to assist!

    Based on your description regarding Active Explorer vs Active Inspector Code, please comprehend that our support is for Outlook basic issues, and do not have resource about development related. Microsoft have specific dedicated teams who are handling development related queries, and they have special expertise in it. So, it is recommended to kindly post your query to dedicated team via Office Development - Microsoft Q&A. Engineers who are dedicated into this environment with rich experience and more resources can then assist efficiently. We believe they would conduct in-depth research on the problem you encountered and provide you with more professional assistance.

    In the meantime, I would also like to invite community members and MVPs in the forum to share their knowledge or any workaround and insight on this topic.

    Thanks for your precious time and your understanding would be highly appreciated. Have a nice day!

    Sincerely,

    Sherry | Microsoft Community Moderator

    Was this answer helpful?

    0 comments No comments