View Full Version : Remove Hyperlink from Image in VBA
CaptainDash
04-27-2016, 03:31 AM
Hi,
I have an issue, where a daily email is sent to me with some text and an image. The image in the email has a hyperlink attached to it. I need to set up a rule which forwards the email on with the hyperlink removed (as it won't work for any of the recipients and will create a million complaints!) and ideal all the text before the image removed as well. I'm a complete novice in Outlook VBA, so any help is massively appreciated.
gmayor
04-27-2016, 06:45 AM
Without seeing the message one can only make educated guesses at what is required, but the following script run from a rule that identifies the particular messages as they arrive in the inbox will forward the message to the named recipient having removed the hyperlink from the first image and any text before that image. I have included a macro to test the process on a selected message already downloaded.
Option Explicit
Sub TestScript()
Dim olMsg As MailItem
On Error Resume Next
Set olMsg = ActiveExplorer.Selection.Item(1)
ForwardWithEdits olMsg
lbl_Exit:
Exit Sub
End Sub
Sub ForwardWithEdits(olItem As MailItem)
Dim olInsp As Outlook.Inspector
Dim wdDoc As Object
Dim oRng As Object
Dim oLink As Object
Dim oShape As Object
Dim olFwd As MailItem
On Error Resume Next
Set olFwd = olItem.Forward
With olFwd
.BodyFormat = olFormatHTML
.To = "someone@somewhere.com" 'The address of the person to whom the message is to be forwarded.
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
Set oRng = wdDoc.Range(0, 0)
.Display 'do not remove this line
For Each oShape In wdDoc.Range.inlineshapes
Set oLink = oShape.hyperlink
If Not oLink Is Nothing Then
oShape.hyperlink.Delete
oRng.End = oShape.Range.start
oRng.Delete
Exit For
End If
Next oShape
'.Send 'Remove the apostrophe from the start of this line after testing
End With
lbl_Exit:
Exit Sub
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.