Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2006

Tip: Looking for answers? Try searching our database.

Style replacement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve C - 17 Feb 2006 03:35 GMT
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!
Edward Thrashcort - 17 Feb 2006 09:23 GMT
Wouldn't it be easier simply to use Format Style Modify?

Eddie

> *From:* "Steve C <SteveC@discussions.microsoft.com>
> *Date:* Thu, 16 Feb 2006 19:35:03 -0800
[quoted text clipped - 5 lines]
> indents, tabs, paragraph formatting, etc. with updated ones (keeping the
> same style names).  Any suggestions would be appreciated!
Steve C - 17 Feb 2006 13:49 GMT
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.

> Wouldn't it be easier simply to use Format Style Modify?
>
[quoted text clipped - 9 lines]
> > indents, tabs, paragraph formatting, etc. with updated ones (keeping the
> > same style names).  Any suggestions would be appreciated!
Graham Mayor - 17 Feb 2006 15:14 GMT
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

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> 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
[quoted text clipped - 14 lines]
>>> with updated ones (keeping the same style names).  Any suggestions
>>> would be appreciated!
Steve C - 17 Feb 2006 17:28 GMT
Graham,

Your code is extremely helpful.  Thank you so much.

> 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.
[quoted text clipped - 55 lines]
> >>> with updated ones (keeping the same style names).  Any suggestions
> >>> would be appreciated!
Graham Mayor - 18 Feb 2006 07:52 GMT
You are welcome

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Graham,
>
[quoted text clipped - 68 lines]
>>>>> formatting, etc. with updated ones (keeping the same style
>>>>> names).  Any suggestions would be appreciated!
William Meisheid - 17 Feb 2006 13:34 GMT
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?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.