Reply
 
Thread Tools Display Modes
  #1   Report Post  
Tom Brindley (Todeka)
 
Posts: n/a
Default How can I use a relative filepath when linking to picture

When linking pictures {IncludePicture "Filename"} in Word, the file path is
always absoute, making it difficult to distribute. Is there any way of
entering a relative filepath?
  #2   Report Post  
macropod
 
Posts: n/a
Default

Hi Tom,

You can't enter a relative filepath. However, if you're going to keep the
document and pictures in the same folder for distribution, you could add the
following code to a vba module in the document:

Option Explicit
Public SFileName As String

Sub AutoOpen()
' This routine runs whenever the document is opened. It mainly performs a
set of housekeeping functions.
' Most of the work is done by the UpdateFields and GetSourceFileName
routines.
Dim sBar As Boolean, oSection As Section, shp As Shape, oHeadFoot As
HeaderFooter
sBar = Application.DisplayStatusBar ' Store StatusBar visibility condition
Application.DisplayStatusBar = True ' Make StatusBar visible
Application.ScreenUpdating = False ' Minimise screen flicker
Selection.EndKey Unit:=wdStory
ActiveWindow.View.ShowFieldCodes = True
Call UpdateFields
' Set the saved status of the document to true, so that path update changes
via this macro are ignored.
' Since they'll be recreated the next time the document is opened, saving
such changes doesn't really matter.
' Then clean up and exit.
ActiveDocument.Saved = True
ActiveWindow.View.ShowFieldCodes = False
On Error Resume Next ' In case there's only one active pane
ActiveWindow.ActivePane.Close
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
Application.DisplayStatusBar = sBar ' Restore StatusBar to original
visibility condition
Selection.HomeKey Unit:=wdStory
Application.ScreenUpdating = True
End Sub

Private Sub UpdateFields()
' This routine sets the new path for external field references, calls the
GetSourceFileName routine to get the
' link's filename, plus any bookmarks and switches from the original field
then merges these into a new field.
Dim wdRange As Range, FieldCount As Integer, FieldType As String, NewPath As
String, NewField As String
' Get the new path
NewPath = Replace$(ActiveDocument.Path, "\", "\\") & "\\"
' Go through the document, updating all external field links with the new
path.
For Each wdRange In ActiveDocument.StoryRanges
If wdRange.Fields.Count 0 Then
For FieldCount = wdRange.Fields.Count To 1 Step -1
wdRange.Fields(FieldCount).Select
With wdRange.Fields(FieldCount)
Select Case True
Case .Type = wdFieldHyperlink
FieldType = "HYPERLINK"
Case .Type = wdFieldIncludeText
FieldType = "INCLUDETEXT"
Case .Type = wdFieldIncludePicture
FieldType = "INCLUDEPICTURE"
Case .Type = wdFieldLink
FieldType = "LINK"
Case .Type = wdFieldRefDoc
FieldType = "RD"
Case Else
FieldType = ""
End Select
End With
If FieldType "" Then
Call GetSourceFileName
NewField = FieldType & " " & """" & NewPath & SFileName
Application.StatusBar = "Updating " & SFileName ' Show
progress on status bar
With Selection
.Delete
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:=NewField, PreserveFormatting:=False
End With
End If
Next FieldCount
End If
Next wdRange
Application.StatusBar = "Finished!"
End Sub

Private Sub GetSourceFileName()
' This routine gets the source file's name, plus any bookmarks and switches
from the original field.
Dim CharPos As Integer
SFileName = Selection
For CharPos = Len(SFileName) To 0 Step -1
On Error Resume Next 'In case there's no path
If Mid(SFileName, CharPos, 2) = "\\" Then
SFileName = Mid(SFileName, CharPos + 2)
Exit For
End If
Next CharPos
'Delete any extra spaces on the right, but preserve leading & internal
spacing.
SFileName = RTrim(Replace$(SFileName, Chr(21), ""))
End Sub


The above code automatically updates the all external links (not just for
pictures) every time the document is opened.

Cheers


"Tom Brindley (Todeka)" Tom Brindley
wrote in message ...
When linking pictures {IncludePicture "Filename"} in Word, the file path

is
always absoute, making it difficult to distribute. Is there any way of
entering a relative filepath?



  #3   Report Post  
PhotoJoe
 
Posts: n/a
Default

Hey "macropod",

If I read all the comment notes in your vba module code correctly, I can use
this same vba module to play some mp3 files from links created in a mht file.
Is that correct I hope?

I'm not quite sure how to insert the vba code into a mht file, can you
explain.? Also does the code begin with "Option Explicit" or "Sub AutoOpen"?

Thanks,
Joe

"macropod" wrote:

Hi Tom,

You can't enter a relative filepath. However, if you're going to keep the
document and pictures in the same folder for distribution, you could add the
following code to a vba module in the document:

Option Explicit
Public SFileName As String

Sub AutoOpen()
' This routine runs whenever the document is opened. It mainly performs a
set of housekeeping functions.
' Most of the work is done by the UpdateFields and GetSourceFileName
routines.
Dim sBar As Boolean, oSection As Section, shp As Shape, oHeadFoot As
HeaderFooter
sBar = Application.DisplayStatusBar ' Store StatusBar visibility condition
Application.DisplayStatusBar = True ' Make StatusBar visible
Application.ScreenUpdating = False ' Minimise screen flicker
Selection.EndKey Unit:=wdStory
ActiveWindow.View.ShowFieldCodes = True
Call UpdateFields
' Set the saved status of the document to true, so that path update changes
via this macro are ignored.
' Since they'll be recreated the next time the document is opened, saving
such changes doesn't really matter.
' Then clean up and exit.
ActiveDocument.Saved = True
ActiveWindow.View.ShowFieldCodes = False
On Error Resume Next ' In case there's only one active pane
ActiveWindow.ActivePane.Close
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
Application.DisplayStatusBar = sBar ' Restore StatusBar to original
visibility condition
Selection.HomeKey Unit:=wdStory
Application.ScreenUpdating = True
End Sub

Private Sub UpdateFields()
' This routine sets the new path for external field references, calls the
GetSourceFileName routine to get the
' link's filename, plus any bookmarks and switches from the original field
then merges these into a new field.
Dim wdRange As Range, FieldCount As Integer, FieldType As String, NewPath As
String, NewField As String
' Get the new path
NewPath = Replace$(ActiveDocument.Path, "\", "\\") & "\\"
' Go through the document, updating all external field links with the new
path.
For Each wdRange In ActiveDocument.StoryRanges
If wdRange.Fields.Count 0 Then
For FieldCount = wdRange.Fields.Count To 1 Step -1
wdRange.Fields(FieldCount).Select
With wdRange.Fields(FieldCount)
Select Case True
Case .Type = wdFieldHyperlink
FieldType = "HYPERLINK"
Case .Type = wdFieldIncludeText
FieldType = "INCLUDETEXT"
Case .Type = wdFieldIncludePicture
FieldType = "INCLUDEPICTURE"
Case .Type = wdFieldLink
FieldType = "LINK"
Case .Type = wdFieldRefDoc
FieldType = "RD"
Case Else
FieldType = ""
End Select
End With
If FieldType "" Then
Call GetSourceFileName
NewField = FieldType & " " & """" & NewPath & SFileName
Application.StatusBar = "Updating " & SFileName ' Show
progress on status bar
With Selection
.Delete
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:=NewField, PreserveFormatting:=False
End With
End If
Next FieldCount
End If
Next wdRange
Application.StatusBar = "Finished!"
End Sub

Private Sub GetSourceFileName()
' This routine gets the source file's name, plus any bookmarks and switches
from the original field.
Dim CharPos As Integer
SFileName = Selection
For CharPos = Len(SFileName) To 0 Step -1
On Error Resume Next 'In case there's no path
If Mid(SFileName, CharPos, 2) = "\\" Then
SFileName = Mid(SFileName, CharPos + 2)
Exit For
End If
Next CharPos
'Delete any extra spaces on the right, but preserve leading & internal
spacing.
SFileName = RTrim(Replace$(SFileName, Chr(21), ""))
End Sub


The above code automatically updates the all external links (not just for
pictures) every time the document is opened.

Cheers


"Tom Brindley (Todeka)" Tom Brindley
wrote in message ...
When linking pictures {IncludePicture "Filename"} in Word, the file path

is
always absoute, making it difficult to distribute. Is there any way of
entering a relative filepath?




  #4   Report Post  
macropod
 
Posts: n/a
Default

Hi PhotoJoe,

The code is for a Microsoft Word document (ie file extension .dot or .doc).
I have no idea whether it would work in a mht file.

As for your other question, the code begins with "Option Explicit".

Cheers


"PhotoJoe" wrote in message
...
Hey "macropod",

If I read all the comment notes in your vba module code correctly, I can

use
this same vba module to play some mp3 files from links created in a mht

file.
Is that correct I hope?

I'm not quite sure how to insert the vba code into a mht file, can you
explain.? Also does the code begin with "Option Explicit" or "Sub

AutoOpen"?

Thanks,
Joe

"macropod" wrote:

Hi Tom,

You can't enter a relative filepath. However, if you're going to keep

the
document and pictures in the same folder for distribution, you could add

the
following code to a vba module in the document:

Option Explicit
Public SFileName As String

Sub AutoOpen()
' This routine runs whenever the document is opened. It mainly performs

a
set of housekeeping functions.
' Most of the work is done by the UpdateFields and GetSourceFileName
routines.
Dim sBar As Boolean, oSection As Section, shp As Shape, oHeadFoot As
HeaderFooter
sBar = Application.DisplayStatusBar ' Store StatusBar visibility

condition
Application.DisplayStatusBar = True ' Make StatusBar visible
Application.ScreenUpdating = False ' Minimise screen flicker
Selection.EndKey Unit:=wdStory
ActiveWindow.View.ShowFieldCodes = True
Call UpdateFields
' Set the saved status of the document to true, so that path update

changes
via this macro are ignored.
' Since they'll be recreated the next time the document is opened,

saving
such changes doesn't really matter.
' Then clean up and exit.
ActiveDocument.Saved = True
ActiveWindow.View.ShowFieldCodes = False
On Error Resume Next ' In case there's only one active pane
ActiveWindow.ActivePane.Close
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
Application.DisplayStatusBar = sBar ' Restore StatusBar to original
visibility condition
Selection.HomeKey Unit:=wdStory
Application.ScreenUpdating = True
End Sub

Private Sub UpdateFields()
' This routine sets the new path for external field references, calls

the
GetSourceFileName routine to get the
' link's filename, plus any bookmarks and switches from the original

field
then merges these into a new field.
Dim wdRange As Range, FieldCount As Integer, FieldType As String,

NewPath As
String, NewField As String
' Get the new path
NewPath = Replace$(ActiveDocument.Path, "\", "\\") & "\\"
' Go through the document, updating all external field links with the

new
path.
For Each wdRange In ActiveDocument.StoryRanges
If wdRange.Fields.Count 0 Then
For FieldCount = wdRange.Fields.Count To 1 Step -1
wdRange.Fields(FieldCount).Select
With wdRange.Fields(FieldCount)
Select Case True
Case .Type = wdFieldHyperlink
FieldType = "HYPERLINK"
Case .Type = wdFieldIncludeText
FieldType = "INCLUDETEXT"
Case .Type = wdFieldIncludePicture
FieldType = "INCLUDEPICTURE"
Case .Type = wdFieldLink
FieldType = "LINK"
Case .Type = wdFieldRefDoc
FieldType = "RD"
Case Else
FieldType = ""
End Select
End With
If FieldType "" Then
Call GetSourceFileName
NewField = FieldType & " " & """" & NewPath & SFileName
Application.StatusBar = "Updating " & SFileName ' Show
progress on status bar
With Selection
.Delete
.Fields.Add Range:=Selection.Range,

Type:=wdFieldEmpty,
Text:=NewField, PreserveFormatting:=False
End With
End If
Next FieldCount
End If
Next wdRange
Application.StatusBar = "Finished!"
End Sub

Private Sub GetSourceFileName()
' This routine gets the source file's name, plus any bookmarks and

switches
from the original field.
Dim CharPos As Integer
SFileName = Selection
For CharPos = Len(SFileName) To 0 Step -1
On Error Resume Next 'In case there's no path
If Mid(SFileName, CharPos, 2) = "\\" Then
SFileName = Mid(SFileName, CharPos + 2)
Exit For
End If
Next CharPos
'Delete any extra spaces on the right, but preserve leading & internal
spacing.
SFileName = RTrim(Replace$(SFileName, Chr(21), ""))
End Sub


The above code automatically updates the all external links (not just

for
pictures) every time the document is opened.

Cheers


"Tom Brindley (Todeka)" Tom Brindley


wrote in message

...
When linking pictures {IncludePicture "Filename"} in Word, the file

path
is
always absoute, making it difficult to distribute. Is there any way

of
entering a relative filepath?






  #5   Report Post  
Posted to microsoft.public.word.docmanagement
dmartins dmartins is offline
external usenet poster
 
Posts: 2
Default How can I use a relative filepath when linking to picture

I got the same problem with Word 2007. Isn't it solved?

"macropod" escreveu:

Hi Tom,

You can't enter a relative filepath. However, if you're going to keep the
document and pictures in the same folder for distribution, you could add the
following code to a vba module in the document:

Option Explicit
Public SFileName As String

Sub AutoOpen()
' This routine runs whenever the document is opened. It mainly performs a
set of housekeeping functions.
' Most of the work is done by the UpdateFields and GetSourceFileName
routines.
Dim sBar As Boolean, oSection As Section, shp As Shape, oHeadFoot As
HeaderFooter
sBar = Application.DisplayStatusBar ' Store StatusBar visibility condition
Application.DisplayStatusBar = True ' Make StatusBar visible
Application.ScreenUpdating = False ' Minimise screen flicker
Selection.EndKey Unit:=wdStory
ActiveWindow.View.ShowFieldCodes = True
Call UpdateFields
' Set the saved status of the document to true, so that path update changes
via this macro are ignored.
' Since they'll be recreated the next time the document is opened, saving
such changes doesn't really matter.
' Then clean up and exit.
ActiveDocument.Saved = True
ActiveWindow.View.ShowFieldCodes = False
On Error Resume Next ' In case there's only one active pane
ActiveWindow.ActivePane.Close
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
Application.DisplayStatusBar = sBar ' Restore StatusBar to original
visibility condition
Selection.HomeKey Unit:=wdStory
Application.ScreenUpdating = True
End Sub

Private Sub UpdateFields()
' This routine sets the new path for external field references, calls the
GetSourceFileName routine to get the
' link's filename, plus any bookmarks and switches from the original field
then merges these into a new field.
Dim wdRange As Range, FieldCount As Integer, FieldType As String, NewPath As
String, NewField As String
' Get the new path
NewPath = Replace$(ActiveDocument.Path, "\", "\\") & "\\"
' Go through the document, updating all external field links with the new
path.
For Each wdRange In ActiveDocument.StoryRanges
If wdRange.Fields.Count 0 Then
For FieldCount = wdRange.Fields.Count To 1 Step -1
wdRange.Fields(FieldCount).Select
With wdRange.Fields(FieldCount)
Select Case True
Case .Type = wdFieldHyperlink
FieldType = "HYPERLINK"
Case .Type = wdFieldIncludeText
FieldType = "INCLUDETEXT"
Case .Type = wdFieldIncludePicture
FieldType = "INCLUDEPICTURE"
Case .Type = wdFieldLink
FieldType = "LINK"
Case .Type = wdFieldRefDoc
FieldType = "RD"
Case Else
FieldType = ""
End Select
End With
If FieldType "" Then
Call GetSourceFileName
NewField = FieldType & " " & """" & NewPath & SFileName
Application.StatusBar = "Updating " & SFileName ' Show
progress on status bar
With Selection
.Delete
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:=NewField, PreserveFormatting:=False
End With
End If
Next FieldCount
End If
Next wdRange
Application.StatusBar = "Finished!"
End Sub

Private Sub GetSourceFileName()
' This routine gets the source file's name, plus any bookmarks and switches
from the original field.
Dim CharPos As Integer
SFileName = Selection
For CharPos = Len(SFileName) To 0 Step -1
On Error Resume Next 'In case there's no path
If Mid(SFileName, CharPos, 2) = "\\" Then
SFileName = Mid(SFileName, CharPos + 2)
Exit For
End If
Next CharPos
'Delete any extra spaces on the right, but preserve leading & internal
spacing.
SFileName = RTrim(Replace$(SFileName, Chr(21), ""))
End Sub


The above code automatically updates the all external links (not just for
pictures) every time the document is opened.

Cheers


"Tom Brindley (Todeka)" Tom Brindley
wrote in message ...
When linking pictures {IncludePicture "Filename"} in Word, the file path

is
always absoute, making it difficult to distribute. Is there any way of
entering a relative filepath?






  #6   Report Post  
Posted to microsoft.public.word.docmanagement
macropod[_2_] macropod[_2_] is offline
external usenet poster
 
Posts: 2,059
Default How can I use a relative filepath when linking to picture

To see how to implement relative paths in Word, check out the solution I've posted at:
http://www.wopr.com/cgi-bin/w3t/show...?Number=670027

--
Cheers
macropod
[MVP - Microsoft Word]


"dmartins" wrote in message ...
I got the same problem with Word 2007. Isn't it solved?

"macropod" escreveu:

Hi Tom,

You can't enter a relative filepath. However, if you're going to keep the
document and pictures in the same folder for distribution, you could add the
following code to a vba module in the document:

Option Explicit
Public SFileName As String

Sub AutoOpen()
' This routine runs whenever the document is opened. It mainly performs a
set of housekeeping functions.
' Most of the work is done by the UpdateFields and GetSourceFileName
routines.
Dim sBar As Boolean, oSection As Section, shp As Shape, oHeadFoot As
HeaderFooter
sBar = Application.DisplayStatusBar ' Store StatusBar visibility condition
Application.DisplayStatusBar = True ' Make StatusBar visible
Application.ScreenUpdating = False ' Minimise screen flicker
Selection.EndKey Unit:=wdStory
ActiveWindow.View.ShowFieldCodes = True
Call UpdateFields
' Set the saved status of the document to true, so that path update changes
via this macro are ignored.
' Since they'll be recreated the next time the document is opened, saving
such changes doesn't really matter.
' Then clean up and exit.
ActiveDocument.Saved = True
ActiveWindow.View.ShowFieldCodes = False
On Error Resume Next ' In case there's only one active pane
ActiveWindow.ActivePane.Close
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
Application.DisplayStatusBar = sBar ' Restore StatusBar to original
visibility condition
Selection.HomeKey Unit:=wdStory
Application.ScreenUpdating = True
End Sub

Private Sub UpdateFields()
' This routine sets the new path for external field references, calls the
GetSourceFileName routine to get the
' link's filename, plus any bookmarks and switches from the original field
then merges these into a new field.
Dim wdRange As Range, FieldCount As Integer, FieldType As String, NewPath As
String, NewField As String
' Get the new path
NewPath = Replace$(ActiveDocument.Path, "\", "\\") & "\\"
' Go through the document, updating all external field links with the new
path.
For Each wdRange In ActiveDocument.StoryRanges
If wdRange.Fields.Count 0 Then
For FieldCount = wdRange.Fields.Count To 1 Step -1
wdRange.Fields(FieldCount).Select
With wdRange.Fields(FieldCount)
Select Case True
Case .Type = wdFieldHyperlink
FieldType = "HYPERLINK"
Case .Type = wdFieldIncludeText
FieldType = "INCLUDETEXT"
Case .Type = wdFieldIncludePicture
FieldType = "INCLUDEPICTURE"
Case .Type = wdFieldLink
FieldType = "LINK"
Case .Type = wdFieldRefDoc
FieldType = "RD"
Case Else
FieldType = ""
End Select
End With
If FieldType "" Then
Call GetSourceFileName
NewField = FieldType & " " & """" & NewPath & SFileName
Application.StatusBar = "Updating " & SFileName ' Show
progress on status bar
With Selection
.Delete
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:=NewField, PreserveFormatting:=False
End With
End If
Next FieldCount
End If
Next wdRange
Application.StatusBar = "Finished!"
End Sub

Private Sub GetSourceFileName()
' This routine gets the source file's name, plus any bookmarks and switches
from the original field.
Dim CharPos As Integer
SFileName = Selection
For CharPos = Len(SFileName) To 0 Step -1
On Error Resume Next 'In case there's no path
If Mid(SFileName, CharPos, 2) = "\\" Then
SFileName = Mid(SFileName, CharPos + 2)
Exit For
End If
Next CharPos
'Delete any extra spaces on the right, but preserve leading & internal
spacing.
SFileName = RTrim(Replace$(SFileName, Chr(21), ""))
End Sub


The above code automatically updates the all external links (not just for
pictures) every time the document is opened.

Cheers


"Tom Brindley (Todeka)" Tom Brindley
wrote in message ...
When linking pictures {IncludePicture "Filename"} in Word, the file path

is
always absoute, making it difficult to distribute. Is there any way of
entering a relative filepath?




  #7   Report Post  
Posted to microsoft.public.word.docmanagement
dmartins dmartins is offline
external usenet poster
 
Posts: 2
Default How can I use a relative filepath when linking to picture

thanks macropod. it did work. I just can't imagine why that microsoft guys
havent already done it for us.

"macropod" escreveu:

To see how to implement relative paths in Word, check out the solution I've posted at:
http://www.wopr.com/cgi-bin/w3t/show...?Number=670027

--
Cheers
macropod
[MVP - Microsoft Word]


"dmartins" wrote in message ...
I got the same problem with Word 2007. Isn't it solved?

"macropod" escreveu:

Hi Tom,

You can't enter a relative filepath. However, if you're going to keep the
document and pictures in the same folder for distribution, you could add the
following code to a vba module in the document:

Option Explicit
Public SFileName As String

Sub AutoOpen()
' This routine runs whenever the document is opened. It mainly performs a
set of housekeeping functions.
' Most of the work is done by the UpdateFields and GetSourceFileName
routines.
Dim sBar As Boolean, oSection As Section, shp As Shape, oHeadFoot As
HeaderFooter
sBar = Application.DisplayStatusBar ' Store StatusBar visibility condition
Application.DisplayStatusBar = True ' Make StatusBar visible
Application.ScreenUpdating = False ' Minimise screen flicker
Selection.EndKey Unit:=wdStory
ActiveWindow.View.ShowFieldCodes = True
Call UpdateFields
' Set the saved status of the document to true, so that path update changes
via this macro are ignored.
' Since they'll be recreated the next time the document is opened, saving
such changes doesn't really matter.
' Then clean up and exit.
ActiveDocument.Saved = True
ActiveWindow.View.ShowFieldCodes = False
On Error Resume Next ' In case there's only one active pane
ActiveWindow.ActivePane.Close
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
Application.DisplayStatusBar = sBar ' Restore StatusBar to original
visibility condition
Selection.HomeKey Unit:=wdStory
Application.ScreenUpdating = True
End Sub

Private Sub UpdateFields()
' This routine sets the new path for external field references, calls the
GetSourceFileName routine to get the
' link's filename, plus any bookmarks and switches from the original field
then merges these into a new field.
Dim wdRange As Range, FieldCount As Integer, FieldType As String, NewPath As
String, NewField As String
' Get the new path
NewPath = Replace$(ActiveDocument.Path, "\", "\\") & "\\"
' Go through the document, updating all external field links with the new
path.
For Each wdRange In ActiveDocument.StoryRanges
If wdRange.Fields.Count 0 Then
For FieldCount = wdRange.Fields.Count To 1 Step -1
wdRange.Fields(FieldCount).Select
With wdRange.Fields(FieldCount)
Select Case True
Case .Type = wdFieldHyperlink
FieldType = "HYPERLINK"
Case .Type = wdFieldIncludeText
FieldType = "INCLUDETEXT"
Case .Type = wdFieldIncludePicture
FieldType = "INCLUDEPICTURE"
Case .Type = wdFieldLink
FieldType = "LINK"
Case .Type = wdFieldRefDoc
FieldType = "RD"
Case Else
FieldType = ""
End Select
End With
If FieldType "" Then
Call GetSourceFileName
NewField = FieldType & " " & """" & NewPath & SFileName
Application.StatusBar = "Updating " & SFileName ' Show
progress on status bar
With Selection
.Delete
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:=NewField, PreserveFormatting:=False
End With
End If
Next FieldCount
End If
Next wdRange
Application.StatusBar = "Finished!"
End Sub

Private Sub GetSourceFileName()
' This routine gets the source file's name, plus any bookmarks and switches
from the original field.
Dim CharPos As Integer
SFileName = Selection
For CharPos = Len(SFileName) To 0 Step -1
On Error Resume Next 'In case there's no path
If Mid(SFileName, CharPos, 2) = "\\" Then
SFileName = Mid(SFileName, CharPos + 2)
Exit For
End If
Next CharPos
'Delete any extra spaces on the right, but preserve leading & internal
spacing.
SFileName = RTrim(Replace$(SFileName, Chr(21), ""))
End Sub


The above code automatically updates the all external links (not just for
pictures) every time the document is opened.

Cheers


"Tom Brindley (Todeka)" Tom Brindley
wrote in message ...
When linking pictures {IncludePicture "Filename"} in Word, the file path
is
always absoute, making it difficult to distribute. Is there any way of
entering a relative filepath?




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
File size is huge after linking many png files - Word 2003 (build 11.5604.6412) L Mehl Microsoft Word Help 4 July 21st 05 07:19 AM
Relative path links DaveO Microsoft Word Help 0 July 20th 05 06:52 PM
Absolute and Relative Hyperlinks in Office 2003 Mia Microsoft Word Help 4 May 22nd 05 10:52 AM
How to creat relative and shorthand file path names? 2dogs Microsoft Word Help 1 May 15th 05 12:11 PM
filepath in footer Treesy Microsoft Word Help 2 May 13th 05 04:46 PM


All times are GMT +1. The time now is 02:04 AM.

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"