Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

Word 2007 Macro - Mass Find and Replace without opening

Jul 20, 2010 5:23AM PDT

We have 1000's of .docx files that have embedded links to Excel documents. The server name was changed/migrated and now when a file is opened, the links are broken/lost/dissappear.
I wrote/modified a word-tips code (below) and it worked fine if I pointed it to one distinct file. It did not work when I tried to un-REM it back to the folder option. Probably because I left the open word doc portions REMed.
We also manually zipped a file, and then edited just the xml piece that contained the path for the embedded link. However in either case I have to do one by one.
Does anyone have macro code, or willing to post something, that would either do a mass find and replace running from some master vehicle word doc taht would do this to all target files in a directory with sub folders? Or, one that would zip all the target word docs, then find and replace/edit just the path portion of the link verbiage in the xml piece? Then save.
Anyone?

Public Sub MassReplace()
Dim Directory As String
Dim FType As String
Dim FName As String

Directory = "X:\Project files\TEST FOLDER\Facilities"
FType = "*.docx"

ChDir Directory
' FName = "X:\Project files\Facility\Project.docx"
FName = Dir(FType)
' for each file you find, run this loop
Do While FName <> ""
' open the file
'Documents.Open FileName:=FName

' search and replace the link server name
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Fileserver"
.MatchCase = True
.Replacement.Text = "FS1"
End With
Selection.Find.Execute Replace:=wdReplaceAll

' save and close the current document
'ActiveDocument.Close wdSaveChanges
ActiveDocument.Save

' look for next matching file
FName = Dir
Loop
End Sub

Discussion is locked

- Collapse -
This looks like a job for ...
Jul 20, 2010 5:29AM PDT

WORDPIPE notes it can "Server renaming or replacement where document links need updating"

(google that.)

- Collapse -
A free macro code example is always better than $99!!
Jul 20, 2010 5:46AM PDT

$99 just seems like way too much for this solution, when I am so close to doing it for free. If I can, as a novice, modify that code and have it work for a specific file, I would think someone could improve my code to work on an entire folder...
I did try funduc v 2.4 but it opens the file first - so a no go.
I was about to download "Microsoft Word Mass Find & Replace Tool 1.0" instant file name: 3rdEyeWeInstaller.mis from www.cetalee.com.au but then it had no valid digital signature, the publisher was listed as unknown, and that website cetalee is for commercial construction developers??? I emailed them, but being in the UK may not get an answer until tomorrow. That one is only $4. But seemed iffy, even though Dodownload.com says NOD32, Dr.Web, and Kapersky found no virus problems.

- Collapse -
Jul 20, 2010 5:50AM PDT

For around

- Collapse -
Thanks Advice taken - will try
Jul 20, 2010 6:12AM PDT

Thanks for the responses, the Boss agrees $99 is worth it.

- Collapse -
Thank you both very much - Advice taken!!
Jul 20, 2010 6:13AM PDT

Thanks for the posts. The Boss agrees - $99 is worth it, will try!

- Collapse -
Actually.... not
Jul 20, 2010 6:43AM PDT

Turns out the $99 is for the lite version that can only change files on your local and not on a network, shared, or fileserver drive. Prices range from $499 single user to $899 server version with $100/hr support support, $30 Cd, $9.99 2 year download insurance... So back to anyone with vba code examples want to take a shot at my code to improve for multi-folder use without opening the files????

- Collapse -
Ahh.
Jul 20, 2010 6:54AM PDT

But what if you cheat?

Copy the files back to your local drive, make the changes, return them to where they were?

Or are there other limitations to this software?

Mark

- Collapse -
Ahh, LOL
Jul 20, 2010 7:23AM PDT

Oh, LOL, that is so funny! Uhh, I can't think why that would not work... Great work around! I'll try and let you know... I will be chuckling for days on this one if it works...

- Collapse -
I admit it. I cheat far too often.
Jul 20, 2010 7:54AM PDT

Cheaters often win.

I often bring up a few cheats I've used over the years. One I used cost a friend a week. I couldn't get the effect I wanted on a Word document. I stood back and thought about it again. Then I took out the paper that just printed and printed on it a second time with the other content I wanted.

Months passed and my friend shows up trying to duplicate my report.

I shared the trick and offered them some aspirin.
Bob

- Collapse -
Yes you can use another solution
Jul 21, 2010 5:22AM PDT