![]() |
|
|
|
#1
|
||||
|
||||
|
That requires a rather different approach. Try the following macro. It converts your document to a table, which it then sorts by reference #. That way, all the references are gouped together. There do seem to be some anomalies/inconsistencies with your data, in that you sometimes have multiple names without references, followed by one or more references in a row, but not always the same number of references as names.
The output table sorts all reference series by the first reference in that series. It seems to produce consistent results. Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument
With .Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
.Text = "\["
.Replacement.Text = "^t"
.Execute Replace:=wdReplaceAll
.Text = "\]*[\;^13]"
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceAll
.Text = "\(*\)"
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
.Text = "^s"
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
.Text = ","
.Wrap = wdFindStop
.Execute
End With
Do While .Find.Found
If .Hyperlinks.Count = 0 Then .Text = vbTab
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
With .Range
.ConvertToTable
With .Tables(1)
.Columns.Width = 36
.Columns(1).Width = 144
.Sort ExcludeHeader:=False, CaseSensitive:=False, LanguageID:=wdEnglishUS, _
FieldNumber:="Column 2", SortFieldType:=wdSortFieldNumeric, SortOrder:=wdSortOrderAscending, _
FieldNumber2:="Column 1", SortFieldType2:=wdSortFieldAlphanumeric, SortOrder2:=wdSortOrderAscending
End With
End With
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#2
|
|||
|
|||
|
Dear Paul,
Many thanks again for the prmpt reply. Your mew VBA solution is great and provided me with many other benefits that I can use. I really appreciate your help. All the best Next I will try to mark this inquiry as SOLVED. Cjeers ![]()
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Heading's Footnote's number is displayed in TOC. How to remove the number in TOC?
|
Orehrepus | Word | 1 | 07-13-2014 12:51 PM |
VBA code to read number of footnote and enter in text
|
rekent | Word VBA | 2 | 05-13-2014 06:53 AM |
Extracting a phone number from a string that contains text and numbers.
|
hommi16 | Excel | 2 | 06-05-2013 09:19 PM |
| number in footnote line | ScientificKat | Word | 2 | 07-09-2012 06:25 AM |
| Footnote text is not aligned with the corresponding number | Patrick1988 | Word | 0 | 08-28-2010 09:33 PM |