Code snippet using OOM : How to modify in-appropriate CSS/HTML tags available in the Outlook e-mail’s HTMLBody ?


Hi,

Please find the following code snippet shows how we can modify/edit/add more or in-appropriate CSS/HTML tags available in the Outlook e-mail’s HTMLBody using Outlook Object Model:

'[Code Snippet - Outlook Object Model 
'[How to modify Outlook e-mail's inappropriate CSS/HTML tags from its HTML Body
...
'Definition
Dim str As String
Dim str1 As String
Dim omailitem As Outlook.MailItem
Dim oattach As Outlook.Attachment
Dim ofolder As Outlook.Folder
 
'str1 stands for CSS/HTML tag that needs to be removed from mail's HTMLBody
str1 = "<myNameisRemote_style_0 <!--.Quote{margin-left:1pt;padding-left:4pt;border-left:#6000002pxsolid;}--=""""" & "></style>"
'Pick the Folder
Set ofolder = Application.Session.PickFolder
'Loop through the items
For Each Item In ofolder.Items
'Select a single item
Set omailitem = Item
str = Trim(omailitem.HTMLBody)
'Check the HTMLBody has "myNameisRemote_style_0" string in this mail using Instr()
If InStr(str, "myNameisRemote_style_0") Then
'If Yes, then replace it
str = Replace(str, str1, " ")
Debug.Print "this has " & str
' Assign the replaced value back to HTMLBody
omailitem.HTMLBody = str
'Save the mail message
omailitem.Save
Else
Debug.Print "Not Problem with <myNameisRemote_style_0 CSS_HTML tags"
End If
Next
....
Skip to main content