View Single Post
  #8   Report Post  
Posted to microsoft.public.word.newusers
macropod macropod is offline
external usenet poster
 
Posts: 1,002
Default Relative Hyperlinks

The macro is for use in a Word document - not an mht file - this is a Word
forum, after all.

--
macropod
[MVP - Microsoft Word]


"Quin" wrote in message
...
I checked, it's there.

When I double-click the .mht, they open in IE (which is what I want). IE
did give a warning about AX content, which I allowed.

"macropod" wrote in message
...
Did you make sure the code was still installed in the target document
after
you'd moved it? Did Word give a macro warning when you opened the
document?

--
macropod
[MVP - Microsoft Word]


"Quin" wrote in message
...
Yes, used code, moved files to another machine, links still pointed to
original path.

Changed AutoOpen to MyAutoOpen, called it from Document.Open, moved
files,
no change.

Thanks for the help. Word could be an easy tool for web pages, you'd

think.


"macropod" wrote in message
...
Hi Quin,

What didn't work? Works for me and I've posted this code quite a few

times
before. This is the first time anyone's suggested it doesn't work.

Did
you
add the code to the target, save it, copy the source and target files
to

a
new folder, then re-open the target?

Cheers

--
macropod
[MVP - Microsoft Word]


"Quin" wrote in message
...
Seems to be the right track, but didn't work.


"macropod" wrote in message
...
Hi Quin,

Links to external files in Word are always absolute. Since you're
keeping
the source and target files in the same folder, you can use the
following
macro to automate the update process.

Option Explicit
Dim TrkStatus As Boolean ' Track Changes flag

Private Sub AutoOpen()
' This routine runs whenever the document is opened.
' It calls on the others to do the real work.
' Prepare the environment.
Call MacroEntry
' Most of the work is done by this routine.
Call UpdateFields
' Set the saved status of the document to true, so that changes

via
' this code are ignored. Since the same changes will be made the
' next time the document is opened, saving them doesn't matter.
ActiveDocument.Saved = True
' Go to the start of the document
Selection.HomeKey Unit:=wdStory
' Clean up and exit.
Call MacroExit
End Sub

Private Sub MacroEntry()
' Store current Track Changes status, then switch off temporarily.
With ActiveDocument
TrkStatus = .TrackRevisions
.TrackRevisions = False
End With
' Turn Off Screen Updating temporarily.
Application.ScreenUpdating = False
End Sub

Private Sub MacroExit()
' Restore original Track Changes status
ActiveDocument.TrackRevisions = TrkStatus
' Restore Screen Updating
Application.ScreenUpdating = True
End Sub

Private Sub UpdateFields()
' This routine sets the new path for external links.
Dim oRange As Word.Range
Dim oField As Word.Field
Dim OldPath As String
Dim NewPath As String
' Set the new path
NewPath = Replace$(ActiveDocument.Path, "\", "\\")
' Go through all story ranges in the document, including shapes,
' headers & footers.
For Each oRange In ActiveDocument.StoryRanges
' Go through the fields in the story range.
For Each oField In oRange.Fields
With oField
' Skip over fields that don't have links to external files
If Not .LinkFormat Is Nothing Then
' Get the old path
OldPath = Replace(.LinkFormat.SourcePath, "\", "\\")
' Replace the link to the external file
.Code.Text = Replace(.Code.Text, OldPath, NewPath)
End If
End With
Next oField
Next oRange
End Sub

Regards

--
macropod
[MVP - Microsoft Word]


"Quin" wrote in message
...
I can't seem to make Hyperlinks relative.

These are just links to other documents in the same folder. If I
clear
the "Update Links on Save", the links get converted to something

like
"C:\585C5E52\Default.htm". Without this cleared, it stores full

path
information, which prevents being able to move the documents to
another
path.