View Single Post
 
Old 10-22-2024, 09:47 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

That should be fairly straightforward:


Code:
Sub Macro1()
Dim oFld As Field
Dim oStory As Range
    For Each oStory In ActiveDocument.StoryRanges
        For Each oFld In oStory.Fields
            If oFld.Type = wdFieldRef Then
                If oFld.Result Like "Part*" Or _
                    oFld.Result Like "Schedule*" Then
                    oFld.Unlink
                End If
            End If
        Next oFld
        If oStory.StoryType <> wdMainTextStory Then
            While Not (oStory.NextStoryRange Is Nothing)
                Set oStory = oStory.NextStoryRange
                For Each oFld In oStory.Fields
                    If oFld.Type = wdFieldRef Then
                        If oFld.Result Like "Part*" Or _
                            oFld.Result Like "Schedule*" Then
                            oFld.Unlink
                        End If
                    End If
                Next oFld
            Wend
        End If
    Next oStory
lbl_Exit:
    Set oStory = Nothing
    Set oFld = Nothing
    Exit Sub
End Sub
Check before and after running the macro with

Code:
Sub Macro2()
Dim oFld As Field
Dim oStory As Range
    For Each oStory In ActiveDocument.StoryRanges
        For Each oFld In oStory.Fields
            If oFld.Type = wdFieldRef Then
                Debug.Print oFld.Result
            End If
        Next oFld
        If oStory.StoryType <> wdMainTextStory Then
            While Not (oStory.NextStoryRange Is Nothing)
                Set oStory = oStory.NextStoryRange
                For Each oFld In oStory.Fields
                    If oFld.Type = wdFieldRef Then
                        Debug.Print oFld.Result
                    End If
                Next oFld
            Wend
        End If
    Next oStory
lbl_Exit:
    Set oStory = Nothing
    Set oFld = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote