Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Mount Prospect, Illinois
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Formatting Runs? (All)

    Am I missing something obvious? It seems there should be a way to get at a 'run' of text in a selection that has the same formatting. There are methods for "BoldRun" and "ItalicRun" to set a run of text to particular formatting, but you can't find how big that run is.

    This is something that's relatively easy to 'see' in the RTF of text, but that's hardly a simple way to do things (and while I'm whining, where's the 'clipboard' object that VB6 has that would let me grab the RTF version of text from the clipboard?).

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

    Re: Formatting Runs? (All)

    You can use Edit | Find or the VBA Find method to find text with specified formatting.

  3. #3
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Mount Prospect, Illinois
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Formatting Runs? (All)

    Nnnnn...no.

    I meant, how do you find how big the run of text is that shares the same formatting? This would help for those folks trying to find the font changes in a paragraph, conversions to odd formats, etc.

    In the general case, it might be best to start with the WordML or RTF and parse from there, but if I'm trying to get some info about just a paragraph or two, it can be a lot of work, checking the characteristics character by character.

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Formatting Runs? (All)

    As Hans mentioned, you can use Find/Replace to find the number of characters that share a particular format.
    Using wildcards
    Find: * & put in the formatting that you're looking for
    Replace: ^& this is the wildcard for replacing what is found with itself
    Hit Replace All. Word will give you a count of the number of replacements.

  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

    Re: Formatting Runs? (All)

    Is there a quick way to convert a range to a tagged format such as RTF or HTML (or WordML, which I don't use yet) without going through a new document-paste-Save As-open cycle?

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

    Re: Formatting Runs? (All)

    You can get the HTML for a range using something like
    <code>
    Function RangetoHTML(inRng As Range) As String
    Dim doc As Document
    Dim strHTML As String

    inRng.Copy
    Set doc = Application.Documents.Add(Visible:=False)
    doc.Content.Paste
    RangetoHTML = doc.HTMLProject.HTMLProjectItems(1).Text
    doc.Close SaveChanges:=False
    Set doc = Nothing
    End Function
    </code>

    but it's not exactly what you'd call "stripped down" html!
    StuartR

  7. #7
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Mount Prospect, Illinois
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Formatting Runs? (All)

    My approach is to use VB (not VBA), which has a Clipboard.GetText(vbCFRTF) which will return the entire RTF as a string. The HTML might be easier to parse, especially as I want XML as my final output, based on info not obvious to Word 2003, and much less messy than WordML.
    I can probably do the same thing using the SDK routines to get the clipboard, but for right now rapid prototyping, the Clipboard object is too easy not to make use of.

Posting Permissions

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