Style replacement

S

Steve C

I need to build a procedure that searches an active document for the
existence of a series of customized styles and replaces existing settings
with updated settings. For example, if styles named SCT and/or ACT exist in
the document, find all instances where they're applied and replace the
indents, tabs, paragraph formatting, etc. with updated ones (keeping the same
style names). Any suggestions would be appreciated!
 
W

William Meisheid

Wouldn't it be simpler to use a template and just apply the changes that way,
since you want the style names to remain the same?
 
S

Steve C

The problem is that I'm dealing with hundreds of existing documents that need
to be changed, and doing them individually isn't an option from a time
standpoint.
 
G

Graham Mayor

Modify the styles in the normal template (or some other preferred template)
then apply that template to the files with the update styles option set.
Manual formatting in the documents may cause some headaches.

Sub ApplyNormalTemplate() 'to all files in a folder
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim NormalPath
'set option to create backups
Options.CreateBackup = True
'set the location of Normal.dot
NormalPath = Chr(34) & _
Options.DefaultFilePath(wdUserTemplatesPath) & _
"\Normal.dot" & Chr(34)
With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
PathToUse = .Directory
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
If Left(PathToUse, 1) = Chr(34) Then
PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2)
End If
myFile = Dir$(PathToUse & "*.doc")
While myFile <> ""
Set myDoc = Documents.Open(PathToUse & myFile)
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = NormalPath
End With
myDoc.Close SaveChanges:=wdSaveChanges
myFile = Dir$()
Wend
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

You are welcome

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top