View Single Post
 
Old 06-30-2015, 03:08 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
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

The number is created by a field { AUTONUMLGL }, but that field does not readily give up its result to VBA e.g.

Code:
Dim ofld As field
    For Each ofld In ActiveDocument.Fields
        If ofld.Type = wdFieldAutoNumLegal Then
            MsgBox ofld.Result
        End If
    Next ofld
shows no values

The example code therefore converts the field in the selected paragraph to plain text, which of course is readily accessible from VBA, which is what the range commands are about.

It may well be inefficient but it works and is reasonably fast. To process all the paargraphs then the following should work - it does with your sample.

Code:
Dim ofld As field
Dim orng As Range
Dim oPara As Paragraph
Const strFind As String = "1.1.1." 'The number sequence to find
    For Each oPara In ActiveDocument.Range.Paragraphs
        If oPara.Range.Fields.Count > 0 Then
            Set ofld = oPara.Range.Fields(1)
            If ofld.Type = wdFieldAutoNumLegal Then
                ofld.Unlink
                Set orng = oPara.Range.Previous
                orng.Collapse 0
                orng.MoveEndUntil Chr(9)
                If orng.Text = strFind Then
                    orng.Select
                    MsgBox orng.Text
                    Exit For
                End If
                ActiveDocument.Undo
            End If
        End If
    Next oPara
__________________
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