PDA

View Full Version : Converting FileName for Word 2003 links



dotsterhendu
08-08-2008, 11:00 AM
I regularly use Word documents (Word 2003) with approximately 300 links to cooresponding "referenced" Excel document. I am trying to create a macro that will allow me to change the chosen Excel reference file for the Word document. At this point I am able to get the macro to change all of the links if I manually enter the path to the Excel document in a textbox in the form of: "C:\\somedirectory\\somefolder\\somefile.xls". This becomes a problem when I try to use FileDialog(msoFileDialogFilePicker) because I can only get this command to return a path in the form of "C:\somedirectory\somefolder\somefile.xls". How would I go about getting the FileDialog command to returning the path in the form of the first string? Would it be better to convert the second string to the form of the first? How would I go about doing this?

Thanks.

macropod
08-08-2008, 03:06 PM
Hi dotsterhendu,

Before investing too much effort, see if my Field Link Updater does what you want:
http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=261488

dotsterhendu
08-08-2008, 03:27 PM
Thank you macropod! I looked through your code and all I needed was 'Replace$(NewPath, "\", "\\")'. One simple line of code and now my macro works. I will give your application a try as it seems that it is a bit more robust than mine. I appreciate the help.

macropod
08-08-2008, 08:47 PM
Hi dotsterhendu,

Some of the code in my Field Link Updater isn't as efficient as I might code it today. I didn't know vba as well then as I do now. For example, today I'd probably replace the code that extracts the old path with something based on:
.LinkFormat.SourcePath

FWIW, if the linked files are kept in the same folder as the Word file, you might find the macro attached to the post here useful:
http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=670027 (http://www.vbaexpress.com/forum/)