Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.newusers
Quin Quin is offline
external usenet poster
 
Posts: 7
Default Relative Hyperlinks

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.



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

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.





  #3   Report Post  
Posted to microsoft.public.word.newusers
Quin Quin is offline
external usenet poster
 
Posts: 7
Default Relative Hyperlinks

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.







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

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.









  #5   Report Post  
Posted to microsoft.public.word.newusers
Quin Quin is offline
external usenet poster
 
Posts: 7
Default Relative Hyperlinks

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.













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

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.













  #7   Report Post  
Posted to microsoft.public.word.newusers
Quin Quin is offline
external usenet poster
 
Posts: 7
Default Relative Hyperlinks

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.















  #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.

















  #9   Report Post  
Posted to microsoft.public.word.newusers
Quin Quin is offline
external usenet poster
 
Posts: 7
Default Relative Hyperlinks

Sorry, is there an MHT forum? Word created and editted these .MHT
documents. It doesn't quite handle .HTM documents.

"macropod" wrote in message
...
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.



















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

Hi Quin,

Perhaps if you ask in one of the Internet Explorer forums.

Cheers

--
macropod
[MVP - Microsoft Word]


"Quin" wrote in message
...
Sorry, is there an MHT forum? Word created and editted these .MHT
documents. It doesn't quite handle .HTM documents.

"macropod" wrote in message
...
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.























  #11   Report Post  
Posted to microsoft.public.word.newusers
Quin Quin is offline
external usenet poster
 
Posts: 7
Default Relative Hyperlinks

You mean a Word question in an Internet Explorer forum?

The question is how to get Word to leave hyperlinks alone.


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

Perhaps if you ask in one of the Internet Explorer forums.

Cheers

--
macropod
[MVP - Microsoft Word]


"Quin" wrote in message
...
Sorry, is there an MHT forum? Word created and editted these .MHT
documents. It doesn't quite handle .HTM documents.

"macropod" wrote in message
...
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.























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

hi Quin,


The question is how to get Word to leave hyperlinks alone.

According to your original post, you wanted Word to update document
hyperlinks when you moved the files to a different folder. "These are just
links to other documents in the same folder". The macro I supplied does that
automatically. Put it in the target document (i.e. the one with the
hyperlink fields) and the fields will be updated next time the document is
opened.

Then you said "When I double-click the .mht, they open in IE". Files with a
".mht" are not Word files - Word document files end in ".doc".

Perhaps if you state clearly what the issue is you're dealing with, it would
help. Are you working with hyperlink fields, or just text that represents a
hyperlink path? There is a significant difference. If you press Alt-F9 in a
Word document, any true hyperlinks will display as { HYPERLINK "hyperlink
path\\hyperlink source" }.

Cheers

--
macropod
[MVP - Microsoft Word]


"Quin" wrote in message
...
You mean a Word question in an Internet Explorer forum?

The question is how to get Word to leave hyperlinks alone.


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

Perhaps if you ask in one of the Internet Explorer forums.

Cheers

--
macropod
[MVP - Microsoft Word]


"Quin" wrote in message
...
Sorry, is there an MHT forum? Word created and editted these .MHT
documents. It doesn't quite handle .HTM documents.

"macropod" wrote in message
...
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.

























  #13   Report Post  
Posted to microsoft.public.word.newusers
Quin Quin is offline
external usenet poster
 
Posts: 7
Default Relative Hyperlinks

Funny, Word created the .MHT file.

In my original post, I didn't want Word to update links, I wanted it to
leave them alone, as relative hyperlinks.

A relative hyperlink, like ../Another.Doc, would work fine. This seems to
me to be just another case of Word "fixing" something that wasn't broken.

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


The question is how to get Word to leave hyperlinks alone.

According to your original post, you wanted Word to update document
hyperlinks when you moved the files to a different folder. "These are just
links to other documents in the same folder". The macro I supplied does
that
automatically. Put it in the target document (i.e. the one with the
hyperlink fields) and the fields will be updated next time the document is
opened.

Then you said "When I double-click the .mht, they open in IE". Files with
a
".mht" are not Word files - Word document files end in ".doc".

Perhaps if you state clearly what the issue is you're dealing with, it
would
help. Are you working with hyperlink fields, or just text that represents
a
hyperlink path? There is a significant difference. If you press Alt-F9 in
a
Word document, any true hyperlinks will display as { HYPERLINK "hyperlink
path\\hyperlink source" }.

Cheers

--
macropod
[MVP - Microsoft Word]


"Quin" wrote in message
...
You mean a Word question in an Internet Explorer forum?

The question is how to get Word to leave hyperlinks alone.


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

Perhaps if you ask in one of the Internet Explorer forums.

Cheers

--
macropod
[MVP - Microsoft Word]


"Quin" wrote in message
...
Sorry, is there an MHT forum? Word created and editted these .MHT
documents. It doesn't quite handle .HTM documents.

"macropod" wrote in message
...
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.



























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


Funny, Word created the .MHT file.


Not of it's own accord - presumably you converted a document to an html
file, via File|Save As.

In my original post, I didn't want Word to update links, I wanted it to
leave them alone, as relative hyperlinks.


The hyperlinks never were relative. Word only works with absolute links.
Even if you omit the path, Word saves it.

A relative hyperlink, like ../Another.Doc, would work fine. This seems to
me to be just another case of Word "fixing" something that wasn't broken.


More like someone not being willing to accept that Word works in a
particular way.

Cheers

--
macropod
[MVP - Microsoft Word]


  #15   Report Post  
Posted to microsoft.public.word.newusers
Bob Buckland ?:-\) Bob   Buckland ?:-\) is offline
external usenet poster
 
Posts: 2,073
Default Relative Hyperlinks

Hi Quin,

Word can open MHT files it opens, as they're encoded to let IE and Word know what app they were created in, by default (Check to see
if there's an IE or Word/IE icon on the .mht files in Windows Explorer.

In some scenarios you're correct, Word will adjust the entries but, be sure you've tried both settings for update links in
Tools=Options=General=[Web Options]
to try to preserve the relative links. In some cases its use will seem a bit backwards.
http://support.microsoft.com/kb/903163/en-us?FR=1

The relative values in the hyperlinks can also be affected by where you open the document in relation to the
settings in Tools=Options=File Locations


The basic usage target of Word web documents was in a corporate environment/intranet where the issue is often one where people move
documents around and with relative links when someone opens a moved document none of the linked content is found. Relative links
are also unsupported in some scenarios where the free Microsoft Word viewer app is involved to view the files.

For public facing web pages MS Word's sister app (MS Office Front Page, well at least through 2003 g) is the app targeted to that
functionallity.

=========
"Quin" wrote in message ...
Funny, Word created the .MHT file.

In my original post, I didn't want Word to update links, I wanted it to leave them alone, as relative hyperlinks.

A relative hyperlink, like ../Another.Doc, would work fine. This seems to me to be just another case of Word "fixing" something
that wasn't broken.
--
I hope this helped you,

Bob Buckland ?:-)
MS Office system products MVP

*Courtesy is not expensive and can pay big dividends


LINKS to the 2007 Office System

1. Read about it, try it, or watch the movie
the 2007 Microsoft Office system info,
online Test Drive, or downloadable beta is at
http://microsoft.com/office/preview

2. Already have 2007 Office System Beta 2?
Send Microsoft your feedback (with pictures)
http://sas.office.microsoft.com/

3. Use the 2007 OfficeOnline website without Office2007

a. Install the ActiveX access control
http://office.microsoft.com/search/r...XT101650581033
b. then visit http://officebeta.iponet.net



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying Relative Hyperlinks Lee Weinreich Microsoft Word Help 2 May 2nd 06 12:21 AM
Relative Hyperlinks Lee Weinreich Microsoft Word Help 2 May 2nd 06 12:16 AM
Hyperlinks -Relative Addresses and Absolute Addresses CristinaP Microsoft Word Help 3 November 18th 05 08:59 AM
Absolute and Relative Hyperlinks in Office 2003 Mia Microsoft Word Help 4 May 22nd 05 10:52 AM
How to make hyperlinks relative in Word 2003 PhotoJoe Microsoft Word Help 1 February 6th 05 07:29 AM


All times are GMT +1. The time now is 08:08 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"