
4,384 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
You can use the Explorer.Selection property, but you'll have to check if one or more messages are selected. For example:
Sub GetSelectedItems()
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim MsgTxt As String
Dim x As Integer
MsgTxt = "You have selected items from: "
Set myOlExp = Application.ActiveExplorer
Set myOlSel = myOlExp.Selection
For x = 1 To myOlSel.Count
MsgTxt = MsgTxt & myOlSel.Item(x).SenderName & ";"
Next x
MsgBox MsgTxt
End Sub