Consulting

Results 1 to 2 of 2

Thread: Remove Hyperlink from Image in VBA

  1. #1

    Remove Hyperlink from Image in VBA

    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.

  2. #2
    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
    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
  •