From: Robin on
Hi -

Basic question, in my Word template I have some linked images. I want to use
VBA to change the path and filename of some of these links ... can anyone
give me a clue as to how I should best do this?

Thanks
Robin
From: macropod on
Hi Robin,

To see how to paths in Word using vba, check out the macro solution I've posted for implement relative paths at:
http://lounge.windowssecrets.com/index.php?showtopic=670027

--
Cheers
macropod
[Microsoft MVP - Word]


"Robin" <Robin(a)discussions.microsoft.com> wrote in message news:7EA2C548-7D01-4515-BCC8-2EF3210439C9(a)microsoft.com...
> Hi -
>
> Basic question, in my Word template I have some linked images. I want to use
> VBA to change the path and filename of some of these links ... can anyone
> give me a clue as to how I should best do this?
>
> Thanks
> Robin
From: Robin on
Hi and thanks for the info, but it's not really what I want. All I want to do
is programatically change the name of the file that is being referenced. For
example if my document (or template file) has a link c:\My Pictures\house.gif
in it, then I want to change that to c:\My Pictures\apartment.gif

thanks
Robin

"macropod" wrote:

> Hi Robin,
>
> To see how to paths in Word using vba, check out the macro solution I've posted for implement relative paths at:
> http://lounge.windowssecrets.com/index.php?showtopic=670027
>
> --
> Cheers
> macropod
> [Microsoft MVP - Word]
>
>

From: macropod on
Hi Robin,

Your original post said "I want to use VBA to change the path and filename", but you gave no details of the criteria to be used for
either (and you still haven't). The link I pointed you to showed how you might go about changing the path automatically. To change
the filename as well (interactively), you could modify the macro as follows:

1. Create two new variables:
Dim OldFile As String
Dim NewFile As String
before:
Dim i As Integer

2. replace everything between:
OldPath = Replace(.LinkFormat.SourcePath, "\", "\\")
and:
End If
with:
' Get the old filename
OldFile = .LinkFormat.SourceName
' Get the new filename
getname:
NewFile = InputBox("What is the New Filename?", "Change Filename", OldFile)
If NewFile = "" Or InStr(NewFile, ".") = 0 Then GoTo getname
' Replace the link to the external file
.Code.Text = Replace(.Code.Text, OldPath & "\\" & OldFile, NewPath & "\\" & NewFile)
..Update

If you don't want to vary the path, simply change:
.Code.Text = Replace(.Code.Text, OldPath & "\\" & OldFile, NewPath & "\\" & NewFile)
to
.Code.Text = Replace(.Code.Text, OldFile, NewFile)
and delete the other bits of code & comments relating to OldPath and NewPath.

If this still doesn't suit, perhaps you could clarify exactly what it is you want to change and the criteria for making the
change(s).

--
Cheers
macropod
[Microsoft MVP - Word]


"Robin" <Robin(a)discussions.microsoft.com> wrote in message news:25FA43A2-6A7B-4AFA-936E-D4B3EEC86BCE(a)microsoft.com...
> Hi and thanks for the info, but it's not really what I want. All I want to do
> is programatically change the name of the file that is being referenced. For
> example if my document (or template file) has a link c:\My Pictures\house.gif
> in it, then I want to change that to c:\My Pictures\apartment.gif
>
> thanks
> Robin
>
> "macropod" wrote:
>
>> Hi Robin,
>>
>> To see how to paths in Word using vba, check out the macro solution I've posted for implement relative paths at:
>> http://lounge.windowssecrets.com/index.php?showtopic=670027
>>
>> --
>> Cheers
>> macropod
>> [Microsoft MVP - Word]
>>
>>
>

From: Fumei2 via OfficeKB.com on
Please try to be very explicit and clear. You write:

For
example if my document (or template file) has a link c:\My Pictures\house.gif

in it, then I want to change that to c:\My Pictures\apartment.gif

Now if you are asking about a hyperlink, you can do something like:

With Selection.Hyperlinks(1)
.Address = "C:\WhatEVER.jpg"
.TextToDisplay = "New text Yadda Yadda"
End With

This changes the hyperlink at the cursor (the Selection) to point to (link) c:
\whatever.jpg, and display the text ""New text Yadda Yadda" as the - well,
the displayed text.

So you change both the actual Address hyperlinked to, AND the text that is
displayed.

Robin wrote:
>Hi -
>
>Basic question, in my Word template I have some linked images. I want to use
>VBA to change the path and filename of some of these links ... can anyone
>give me a clue as to how I should best do this?
>
>Thanks
>Robin

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200912/1