Macro to convert hyperlinks to Word97/2000 Format

M

Mark

Hi there

I have about 80 MS Word documents created in Word 2003 that contain hyperlinks to other files within the same directory tree. The hyperlinks work perfectly well on my PC (WinXP and Off2003), but most of the users accessing the documents (and using the hyperlinks to navigate around) are using Windows 95 with Office 97. These users are unable to follow the hyperlinks. The reason is well documented in MS Knowledge Base article 329835 (entitled "Problems with Hyperlinks in Office XP Documents You Open with Earlier Versions of Office"). Now I would like to convert all the forward slashes in the hyperlinks to backslashes, so that users of all versions of Office and Windows can navigate without encountering errors. However, even though I manually edit the hyperlink in Word 2003 and replace the / with \ when saving the document, the path is stored in the new format (i.e. using the forward slash instead of the backslash character). I have also tried Alt-F9 and the Edit/Replace feature, but even this does not work. Does anyone have any idea how I can convert (preferably using a macro) all the hyperlinks so that they work for all versions of Office since Office 97?

Any feedback would be greatly appreciated. Many thanks in advance.
 
P

Peter Hewett

Hi

Try this code, it replaces "/" with "\" in all hyperlinks. The hyperlinks
can be anywhere in the document.

Sub ConvertHyperlinks()
Dim rngStory As Word.Range
Dim fldTemp As Word.Field
Dim lngIndex As Long

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

Do Until rngStory Is Nothing

' Update all Hyperlink fields
For lngIndex = 1 To rngStory.Fields.Count
Set fldTemp = rngStory.Fields(lngIndex)
If fldTemp.Type = wdFieldHyperlink Then
fldTemp.Code.Text = _
Replace(fldTemp.Code.Text, "/", "\")
End If
Next

' There may be linked stories so make sure we get them as well
Set rngStory = rngStory.NextStoryRange
Loop
Next
End Sub

Please note because I've used the Replace statement this code will only
word in Word 2000 and above.

I hope this helps + 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