Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Mar 2008
    Location
    New York, New York, USA
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'd like to write a VBA macro that will find text that has manual formatting applied on top of the base style. (i.e., anything that would show up in the style list with a +, like "Normal +15p").

    I can't seem to find anything that's helpful.

    I want to avoid analyzing every character in the file, because it will take too long. I thought there might be some function that I'm overlooking.

    Any ideas?

    Thanks,
    John

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You can use code like this:

    Code:
    Selection.HomeKey Unit:=wdStory
    With Selection.Find
      ' Initialize
      .ClearFormatting
      .Format = True
      ' Search for Normal style
      .Style = wdStyleNormal
      ' Plus manual formatting: 15 points
      .Font.Size = 15
      ' Optional: search for specific text
      .Text = "chief"
      ' Go!
      .Execute
    End With

  3. #3
    New Lounger
    Join Date
    Mar 2008
    Location
    New York, New York, USA
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, but that code is extremely specific.

    I was just giving "Normal +15p" as a basic example. But it could be any number of different styles, and any number of formats including fonts, sizes, bold, italic, super/subscript, colors, etc. I was hoping there was a way to just find any style that had extra manual formats applied beyond the underlying style definition.

    Thanks,
    John

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    What do you want to accomplish?


  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    I think I've seen some code that uses the Selection.SelectCurrentFont method to expand a selection to the end of the "run of text" that is in a particular font face or font size. Then you could collapse the selection and look forward and examine the next "run of text" to see whether it conforms to its underlying paragraph style. Still seems arduous, but at least it's not every character.

    Hmmm, but what if the underlying styles actually didn't match but direct formatting had been applied? I suppose this method has its own problems/limitations.

Posting Permissions

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