Link to home
Create AccountLog in
Avatar of Doug Van
Doug VanFlag for Canada

asked on

Word 2013 linked images need relative paths!

Hello all,

I am writing a document where all of the inserted images will be constantly updated. My solution was to insert the image with 'link to file'. So when an image was replaced in folder, F9 or restart Word to see the updated image.

It worked perfectly until I needed to move my document folder to another computer. The document folder structure remained the same BUT the root folder changed. Now, instead of images, I have broken links!

Word 2013 seems to insist on absolute folder locations. That is insane!
Please tell me how to attach an image with a relative folder location. Google search suggested an answer on 'windowsecrets' but the URL is broken.

Thank you much!
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

You could change the links with a macro like this:
Sub ChangePicturesRootfolder()
    Dim ilsh As InlineShape
    Dim sh As Shape
    Dim strNewRoot As String
    Dim strOldRoot As String
    
    strOldRoot = "C:\MyOldPictures"
    strNewRoot = "D:\MyNewPictures"
    
    For Each ilsh In ActiveDocument.InlineShapes
        ilsh.LinkFormat.SourceFullName = Replace(ilsh.LinkFormat.SourceFullName, strOldRoot, strNewRoot)
    Next ilsh
    
    For Each sh In ActiveDocument.Shapes
        sh.LinkFormat.SourceFullName = Replace(sh.LinkFormat.SourceFullName, strOldRoot, strNewRoot)
    Next sh
End Sub

Open in new window

Avatar of Doug Van

ASKER

Hello Graham,

Thank you. Unfortunately, it doesn't work.

I am getting a runtime error 91. Object variable or With block variable not set.

Also, how would I indicate a relative link in the strNewRoot variable?
All my images are in a sub folder 'images' inside the folder that contains the main document.

Thank you
Sorry, I thought that your document comprised linked pictures only. This new code checks the types of shapes and inline shapes
Sub ChangePicturesRootfolder()
    Dim ilsh As InlineShape
    Dim sh As Shape
    Dim strNewRoot As String
    Dim strOldRoot As String
    
    strOldRoot = "C:\MyOldPictures"
    strNewRoot = "D:\MyNewPictures"
    
    For Each ilsh In ActiveDocument.InlineShapes
        If ilsh.Type = wdInlineShapeLinkedPicture Then
            ilsh.LinkFormat.SourceFullName = Replace(ilsh.LinkFormat.SourceFullName, strOldRoot, strNewRoot)
        End If
    Next ilsh
     For Each sh In ActiveDocument.Shapes
        If sh.Type = msoLinkedPicture Then
            sh.LinkFormat.SourceFullName = Replace(sh.LinkFormat.SourceFullName, strOldRoot, strNewRoot)
        End If
    Next sh
End Sub

Open in new window


As far as I know, Microsoft don't support a way of using relative paths with Link fields. I do have some recollection of reading that it can be done by editing the XML, but I don't think that it will be straightforward if many pictures need treating. I'll try to recall where I saw the information and research from there.
Hello Graham,

>Sorry, I thought that your document comprised linked pictures only. This new code
>checks the types of shapes and inline shapes

Actually, I am only using linked images (nothing more) so this is rather odd.

>As far as I know, Microsoft don't support a way of using relative paths with Link fields.

I am trying to wrap my head around the reasoning for this. I wouldn't even have accepted this in the 80's!

I need to use linked images, due to the beta nature of the product I am documenting. But reviewers are seeing broken links when I transfer a zipped copy to them (includes the images folder).

...
So I took apart the docx format (what a mess under the hood!) and found the file I need to modify is: ...\word\_rels\document.xml.rels

The question is how to edit the absolute paths and change them to relative paths?

Original:
Target="file:///C:\Users\user01\Documents\Quick%20Start%20Guide\images\0030_Store_Block_back.jpg"

Is this a valid relative path:

Target="file:images\0030_Store_Block_back.jpg"

or is this valid:

Target="images\0030_Store_Block_back.jpg"

They both seem to work but I haven't fully tested this yet.

Also, is any of the other stuff important to consider... example:
TargetMode="External"/><Relationship Id="rId18"


I really wish I did not have to resort to this manual editing.

Thank you for your help.
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Hello Graham,

Thank you for your assistance. Your effort was appreciated.
Hmm... this manual editing of "document.xml.rels" doesn't seem to fully work because reviewers are still reporting broken links.

I think the only viable solution is finding a way to do on-line collaboration that doesn't require Word and doesn't require SharePoint.
Thanks for the further feedback.
That might be why Microsoft themselves don't support it any more.
I just discovered, this morning, that the problem seems to be affecting Mac users only.

No matter what the problem is, it is ridiculous that Word only directly supports absolute paths! I would not have accepted this even 15 years ago!