Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post

    Styles in document (Windows 2000 and XP)

    I want to create a form with a drop down list that is populated by a list of the styles in a document. There will be two such lists and the purpose of the form will be to select the style to be found and the style to which it is to be changed.

    I am happy with creating the form and getting it to do what I want but I don't know how to get the style information.

    Can someone please help me on that aspect? Many thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Styles in document (Windows 2000 and XP)

    Say that you have a combo box cbxStyles on your UserForm. Populate it in the Initialize event of the form:

    Private Sub UserForm_Initialize()
    Dim stl As Style
    For Each stl In ActiveDocument.Styles
    ' If stl.InUse Then
    Me.cbxStyles.AddItem stl.NameLocal
    ' End If
    Next stl
    Set stl = Nothing
    End Sub

    If you want to list only styles in use, uncomment the If and End If lines.

    Notes:
    - The InUse property may not act as you would expect - all styles that have ever been used in the document are considered to be in use, even if there is currently no text with that style.
    - You will probably want to set the Style property of the combo box to "2 - fmStyleDropDownList" to prevent the user from entering a non-existent style name.

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Styles in document (Windows 2000 and XP)

    This code is copied from a template that I use to clear manual formatting on selected paragraph styles. It populates a list box called lstStyles

    lstStyles.Clear
    For Each stylNext In ActiveDocument.Styles
    If stylNext.InUse And _
    stylNext <> ActiveDocument.Styles(wdStyleDefaultParagraphFont) _
    Then lstStyles.AddItem stylNext.NameLocal
    Next stylNext

    StuartR

  4. #4
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Styles in document (Windows 2000 and XP)

    Thanks Hans, I now have a userform with the two lists and code that finds one style and replaces it with another. Does the same as the built in Find and Replace but much easier to access. Also you can start typing the style whereas the built in one function only allows you to type the first letter of the style, then you have to scroll down.
    I have been promised 600 documents to reformat and this will be a useful tool. Once I know the common substitutions, I'll write a macro for those and then use this for the remainder.
    Again, many thanks.
    Thanks also Stuart, I only saw your post when I came back to post this. I am nonetheless grateful for your taking the trouble to reply.

    Peter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •