Consulting

Results 1 to 4 of 4

Thread: Loop thru the document

  1. #1

    Loop thru the document

    Friends,

    I want loop thru the document (as attached FullWordTest.docx) and return each sentence/paragraph.

    I tried using Paragraph object and Sentence object calls on Active Document
    ActiveDocument.Paragraphs.Count and ActiveDocument.Sentences.Count returns 1 and If I drill down further Paragraph.Range.Text returns no text.

    Request somebody help me in loop thru the document and return each sentence/paragraph.

    Thanks in Advance.
    --AK.

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Your document consists of a load of textboxes. Textboxes are part of the shapes (in this case) so you need to work with them, something like

    [VBA]For Each s In activedocument.Shapes
    If s.Type = msoTextBox Then
    MsgBox s.TextFrame.TextRange.Sentences.Count
    End If
    Next[/VBA]
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    The point being is that text (paragraphs and sentences) in textboxes are NOT included in the document Paragraphs collection. That is why you get the Count = 1.

    You must work with the Shapes collection...as Tony mentioned.

  4. #4
    Tony & Fumei,

    It worked like a fly!!!

    Thanks a ton for your help

    Thanks in Advance
    --AK

Posting Permissions

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