Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detemine/Set Style Index Number -- Compare Style Descriptions

Status
Not open for further replies.

OscarPCG

Technical User
Aug 12, 2004
15
US
How can I determine or set the style index number for all of the styles in a document?

working with - but not shure why [upsidedown] :

Code:
mPara.Format.Style(IndexNumber)

My goal is to get the "format.style.description" property for each style in my document when it loads and compare the description string to any styles that are created with local formatting. (Such as the description for AHead compared to AHead+Bold,Italic).


 
Hi Oscar. You have a number of threads running around this topic.

All Word builtin styles have a .Builtin property. So you can run through those eliminating those out of your loop, if that helps.

You can also use the .Type property to separate out types of styles.

wdStyleTypeCharacter
wdStyleTypeList
wdStyleTypeParagraph
wdStyleTypeTable

Are you trying to truly compare - and what are the consequences of the compare? Or are you trying to remove styles?

Keep Ahead
Delete Ahead + Bold, blah blah

What exactly are you trying to do?

You can get the description of any style by using the .Description property. It is a string, that you COULD parse and compare with another string from another style. But again, what are you trying to achieve?

There is also the .InUse property which is a boolean value of whether the style, any style
is in use. Note however, if a style is used THEN THE TEXT DELETED, the style's InUse is still set to True.

I think if you could be completely clear about your goal your code could run better.



Gerry
 
The overall goal (of this part of my project) is to have a set list of styles that can be used in a document. If a user applies local formatting, I want to flag the formatting (with a wavy underline) and offer the user a suggested course of action (apply set style or keep as is).

The template will be used to standardize formatting of documents so that they can be processed faster.

At this point I am using a case statement to evaluate the style name. If the name matches I would like to execute a simple dialog.
The difficulty that I am having is that the code works for styles given a completely different name, but if is is modified with local formatting, the evaluation does not detect the name change (based on what I see in the Styles & Formatting window pane).

I will post my code...
Thanks Oscar
 
What I have now:

Code:
Sub CheckStyle()
Dim mPara As Paragraph

For Each mPara In ActiveDocument.Paragraphs
    SelectWhat = mPara.Style 'mPara.Format.Style.NameLocal

    Select Case SelectWhat
    Case "AHead" 
         Debug.Print SelectWhat    
    Case "AlphaList"                
         Debug.Print SelectWhat     
    Case "BHead"
         Debug.Print SelectWhat
    Case "Body Text Indent"
         Debug.Print SelectWhat
    Case "Body Text"
         Debug.Print SelectWhat
'...
    Case Else
         mPara.Range.Select
         Selection.Font.UnderlineColor = wdColorPink
         Selection.Font.Underline = wdUnderlineWavyDouble
         MsgBox "This Text is:  " & SelectWhat & Chr(13) & Chr(10) & _
          Chr(13) & Chr(10) & Chr(13) & Chr(10) & _
         "The style will be marked with a double underline. You " & Chr(13) & Chr(10) & _
         "may keep the current style or apply a designated style " & Chr(13) & Chr(10) & _
         "to the marked text after the check is completed.", vbOKOnly, "Style Tools -  Style Check"
    End Select
Next
End Sub

Any help in identifying a predefined style vs. a style created by local formatting would be greatly appreciated, as well as any other advice.


Thanks,
Oscar
 
Well good news and bad.

I have determined that user defined styles do not have an index number, but you can get the built in index style numbers:

Code:
Sub indexStyles()
Dim styleIndexArray(0 To 190)  ' 190 is the highest # I could find
Dim IndexNo As Integer

Do While IndexNo < 191
    On Error Resume Next
    index1 = ActiveDocument.Styles(IndexNo)
    Debug.Print index1 & " -  " & IndexNo 'check the Immediate window
    IndexNo = IndexNo + 1
Loop

End Sub

Hope this helps someone. [profile]

Oscar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top