Link to home
Start Free TrialLog in
Avatar of bazoz
bazoz

asked on

How to change 574 Word docs with 1 macro

I have 574 word docs in 68 folders.

I constantly need to change the header in all docs with a new logo and address details. These are customized documents supplied to individual clients as a system; no two systems will ever be the same.

Is it possible to have each word doc look-up a global macro and use that macro to insert the new logo etc in its header?

That way if I need to make any changes to the macro (i.e. the drive and/or path to the document that contains the logo and address details), I’m only doing it in the one location. That’s going to be a lot easier than changing 574 word files 3 times week.
 
Thanks for the help - sorry 25 points is all I've got
ASKER CERTIFIED SOLUTION
Avatar of Tommy Kinard
Tommy Kinard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bazoz
bazoz

ASKER

Thanks Dragontooth,
That helped. This is the code I have and it works - but I would like it so that the inserted Linked file also gets automatically updated every time the document is opened.
Also, had a go at some code to deal with protected documents – but that didn’t work (see THIS DOES NOT below) – any ideas where I went wrong? Not all documents are protected.

---------- THIS WORKS ---------
Sub ChangeHeaderPath()
Application.ScreenUpdating = Ture
Set fs = Application.FileSearch
With fs
.LookIn = "G:\THEsystem\"
.SearchSubFolders = True
.FileName = "*.doc"
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Documents.Open fs.FoundFiles(i)
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.InsertFile FileName:="I:\THE System\Header.doc", Link:=True
ActiveDocument.Save
ActiveDocument.Close
Next i
Else
MsgBox "There were no files found"
End If
End With
End Sub

---------- THIS DOES NOT ---------
Sub ChangeHeaderPath()
Application.ScreenUpdating = False
Set fs = Application.FileSearch
With fs
.LookIn = "G:\THEsystem\"
.SearchSubFolders = True
.FileName = "*.doc"
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Documents.Open fs.FoundFiles(i)
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect Password:=""
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.InsertFile FileName:="I:\THE System\Header.doc", Link:=True
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="" ' It errors on this line with 'The ToolsProtectDocument statement is currently disabled'
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.InsertFile FileName:="I:\THE System\Header.doc", Link:=True
End If
ActiveDocument.Save
ActiveDocument.Close
Next i
Else
MsgBox "There were no files found"
End If
End With
End Sub
Avatar of bazoz

ASKER

Have fixed the protected documents problem (missed out a line of code). Just the auto update now. And one new question – can you take the value from a text box and use that value as part of a macro?
i.e. I have a text box where I can enter the full path to the Header.doc this value can then be used in the macro above.
On the textbox Yes, it would be accessed like textbox1.text to get the text from the textbox. Not knowing how your macro is written my best guess at how to do this is - have a global variable with a default destination, this way if no one fills in the textbox the process will continue. Assign the global variable with the value in the textbox on the onexit event may need to include some type of validation there also eg verify that the drive and directory exists I would also recommed thet you use the fully qualified path name, if some of the users do not map their drives to "I" your code will break.

Looking into the links update.

dragontooth

Avatar of bazoz

ASKER

Moving the whole project over to InfoPath, too many hurdles to overcome using Word.
But dragontooth can have the points as I did get part of it to work.