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 / April 2006

Tip: Looking for answers? Try searching our database.

Temporary styles not deleted

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Mahoney - 28 Apr 2006 01:55 GMT
Hi

I've written some VBA code which goes through the current document and
removes any styles that aren't defined in a template. It correctly
removes "permanent" styles (ones you define using New Style) but seems
to ignore "temporary" ones (eg. if you select some Normal text and make
it italic, Word will create a new style called Italic). Can anyone tell
me how to check for these "temporary" styles?

Here's the code I'm using:

Dim templateDoc As Word.Document
Dim Styles() As String
Dim CurrentStyle As Integer
Dim wrdStyle As Word.Style
Dim StyleFound As Boolean
Set templateDoc =
Documents.Open(FileName:="U:\Settings\templates\styles.xml",
Visible:=False)
ReDim Styles(templateDoc.Styles.Count)
For CurrentStyle = 0 To templateDoc.Styles.Count - 1
   Styles(CurrentStyle) = templateDoc.Styles(CurrentStyle +
1).NameLocal
Next
For Each wrdStyle In ActiveDocument.Styles
   StyleFound = False
   For CurrentStyle = 0 To templateDoc.Styles.Count
       If wrdStyle.NameLocal = Styles(CurrentStyle) Then
           StyleFound = True
           Exit For
       End If
   Next
   If StyleFound = False Then wrdStyle.Delete
Next
templateDoc.Close

Thanks :)
Chris
Chris Mahoney - 28 Apr 2006 04:20 GMT
I figured it out - Selection.Font.Reset :)

Chris

Rate this thread:






 
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.