unresolved references

W

ward

Hello,

Is there any good way to scan a document for
invalid/broken reference fields (REF) and linked pictures,
i.e. they will display "Error! Reference source not found"
or, in case of a picture, a broken image will be displayed.

Of course it is possible to scan the .Field.Result
property for 'Error ...' and check the file existance of
linked images, but this seems a bit too laborious.

Does Word or VBA have any 'good' and quick way to check
this?

thanks
Ward
 
P

Peter Hewett

Hi Ward

You've stated exactly what you need to do. Once you understand what you
need to do and why, it's not hugely onerous. I've supplied some code to
give you an idea of what's required. It's somewhat convoluted as it checks
all story types and chases down any linked stories as well. The same code
just sets the field result to show using a red font.

Sub LocateBadFields()
Dim rngStory As Word.Range
Dim fldTemp As Word.Field
Dim lngIndex As Long
Dim Story As Variant

' Iterate through all story types
For Each Story In ActiveDocument.StoryRanges

' Look for any "Error" fields
For lngIndex = 1 To Story.Fields.Count
Set fldTemp = Story.Fields(lngIndex)
If Left$(fldTemp.Result, 6) = "Error!" Then
fldTemp.Result.Font.Color = wdColorRed
End If
Next

' There may be linked stories so make sure we cover them as well
Set rngStory = Story.NextStoryRange
Do Until rngStory Is Nothing

' Look for any "Error" fields
For lngIndex = 1 To rngStory.Fields.Count
Set fldTemp = Story.Fields(lngIndex)
If Left$(fldTemp.Result, 6) = "Error!" Then
fldTemp.Result.Font.Color = wdColorRed
End If
Next

' Link to next story (if any)
Set rngStory = rngStory.NextStoryRange
Loop
Next
End Sub

I hope this helps some + Cheers - Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top