Break the links (Ctrl+Shift+F9) on IncludePicture-Fields using VBA

Dear Experts:

 I got a lot of 'IncludePicture'-Fields.

How do I break the links only on those fields (i.e. Ctrl + Shift + F9) leaving all the other field types alone.

This action should be realized on the active Document using a VBA code.

If no 'IncludePicture'-Fields are found the macro is to say so, if there are any and the links have been broken,  a msgbox should retrieve the number of links broken.

Help is more than appreciated. Thank you very much in advance for your valuable help.

Regards, Andreas

Andreas HermleTeam leaderAsked:
Who is Participating?
Give this a try:
Public Sub RemovePicLinks()

    Dim f As Word.Field
    Dim i As Long
    Dim lngCount As Long
    Dim strMessage As String
    For i = ActiveDocument.Fields.Count To 1 Step -1
        Set f = ActiveDocument.Fields(i)
        If f.Type = wdFieldIncludePicture Then
            lngCount = lngCount + 1
        End If
    Next i
    If lngCount > 0 Then
        strMessage = "Complete - " & CStr(lngCount) & " picture links were broken"
        strMessage = "Complete - no picture links were broken"
    End If

    MsgBox strMessage

End Sub

Open in new window

Andreas HermleTeam leaderAuthor Commented:
Hi Andrew:
  great job, this did the trick.  Thank you very much for your professional help.

Regards, Andreas
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.