Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Cape Town, South Africa, South Africa
    Posts
    399
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Identifying Sentence No (Word XP)

    I'm using the following code to establish the number of sentences in a Word document:

    dblLast = ActiveDocument.Sentences.Count

    How do I see if I do a search and select a sentence in the document what the Activesentence value is? I would like to export a section of the document and then 1st do a searth for the start and then determine the end and then loop through the document.

    Thanks

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

    Re: Identifying Sentence No (Word XP)

    Create a range that starts at the beginning of the document and ends at the start of the found range. Then look for Range.Sentences.Count

    Something like...

    <font face="Georgia">
    Sub FindExample()

    Dim rngFromStart As Range

    Set rngFromStart = ActiveDocument.Content

    With ActiveDocument.Content.Find
    .ClearFormatting
    .Text = "Whatever you are searching for"
    Do While .Execute(Forward:=True, Format:=True) = True
    With .Parent
    rngFromStart.End = .End
    MsgBox "Found in sentence " & Str$(rngFromStart.Sentences.Count)
    If .End = ActiveDocument.Content.End Then
    Exit Do
    Else
    .Move Unit:=wdSentence, Count:=1
    End If
    End With
    Loop
    End With
    End Sub
    </font face=georgia>

    StuartR

  3. #3
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Cape Town, South Africa, South Africa
    Posts
    399
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identifying Sentence No (Word XP)

    Thanks Steward for the code. I've changed the code to this:

    With ActiveDocument.Content.Find
    .ClearFormatting
    .Text = "ACCOUNT: 341300"
    Do While .Execute(Forward:=True, Format:=True) = True
    With .Parent
    rngFromStart.End = .End
    dblstartval = (rngFromStart.Sentences.Count)
    End With
    Loop
    End With

    With ActiveDocument.Content.Find
    .ClearFormatting
    .Text = "ACCOUNT: 341400"
    Do While .Execute(Forward:=True, Format:=True) = True
    With .Parent
    rngFromStart.End = .End
    dblendval = (rngFromStart.Sentences.Count)
    End With
    Loop
    End With

    Basicly I'm looking at extracting a section of a word document. I'm using the search to find the first point in the document and then it should look further and Identify the last point (basicly when the new account starts)

    Thanks

Posting Permissions

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