![]() |
|
#7
|
|||
|
|||
|
Quote:
This is an example of programming cobbled together. I started with Graham's excellent code. The second End If is a mistake. If the "Then" part of an IF statement is on the same line, no End If is needed. That second End If should throw an error. The corrected code is: Code:
Sub RefBrokenRemove2()
'Graham Mayor - https://www.gmayor.com - Last updated - 02 Dec 2020
'https://www.msofficeforums.com/word/46089-macro-delete-cross-reference-error-message-when.html
' Remove broken Cross-Reference Fields
' Modified by Charles Kenyon to first update ref fields
'
Dim i As Integer
Dim oStory As range
For Each oStory In ActiveDocument.StoryRanges
For i = oStory.Fields.Count To 1 Step -1
If oStory.Fields(i).Type = wdFieldRef Then
oStory.Fields(i).Update
If oStory.Fields(i).Result = "Error! Reference source not found." Then oStory.Fields(i).Delete
End If
Next i
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
For i = oStory.Fields.Count To 1 Step -1
If oStory.Fields(i).Type = wdFieldRef Then
oStory.Fields(i).Update
If oStory.Fields(i).Result = "Error! Reference source not found." Then oStory.Fields(i).Delete
End If
Next i
Wend
End If
Next oStory
lbl_Exit:
Set oStory = Nothing
Exit Sub
End Sub
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Find {text} and insert cross reference from bookmark
|
Slamzor | Word VBA | 1 | 12-01-2017 05:12 PM |
Hide error message from missing bookmark
|
lodi123 | Word | 2 | 03-28-2017 11:24 PM |
Cross-reference does not maintain formatting from bookmark
|
frannie | Word | 2 | 03-23-2017 04:33 PM |
Weird issue with bookmark and cross-reference
|
Maddog32 | Word | 2 | 06-10-2016 02:39 PM |
Need help with using bookmark and cross-reference
|
mpdsal | Word | 1 | 07-26-2012 01:05 PM |