Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Location
    Sydney Australia
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Evaluate paragraphs in table cell (Word 2000)

    I want to go to a specific cell in a table, select the cell and then evaluate every paragraph in the cell to identify its style. I do not understand the syntax required to evaluate, one by one, the paragraphs in the cell. I assume it is something like:

    Dim currPara As Paragrah

    [ Code to go to the required cell in the table - I can do this bit ]

    'Select the cell
    Selection.SelectCell

    'Evaluate the paragraphs in the cell

    For Each currPara In Selection.Cell

    Do something... [ I can do this bit ]

    Next currPara

    I would appreciate some guidance, having never used a For...Next Control Statement before.

    Thanks in advance

    PeteF

  2. #2
    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: Evaluate paragraphs in table cell (Word 2000)

    Once you are in the cell, you can select the entirety of it using

    Selection.Cells(1).Select

    You can iterate over the paragraphs in the paragraphs collection using

    For Each currPara in Selection.Paragraphs

    Hope this helps.

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Evaluate paragraphs in table cell (Word 2000)

    You can dispense with selecting the cell - as long as the insertion point is anywhere in the cell, the following will work:

    Dim CurPara As Paragraph
    For Each CurPara In Selection.Cells(1).Range.Paragraphs
    MsgBox CurPara.Style
    Next 'CurPara

    Gary

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

    Re: Evaluate paragraphs in table cell (Word 2000)

    Word VBA allows you to write your code with Select (so it behaves like someone typing at the keyboard). It is usually much better to use Range objects. A Range is exactly the same as a selection except that...
    <UL><LI>You can use multiple ranges in the same document at the same time
    <LI>You can remember a range and return to it
    <LI>Code that manipulates a range tends to run more quicky[/list]You can probably displense with selecting the Cell as well, depending on how you located the table then something like.

    set rngTableRange = {however you found the table}.Range
    For Each CurPara In TableRange.Cells(x,y).Range.Paragraphs

    StuartR

  5. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Evaluate paragraphs in table cell (Word 2000)

    Stuart,

    You're absolutely right about using range objects to do this. The code I posted doesn't select the cell; the presence of "Selection" in the code comes from the assumption that the starting point was going to be the presence of an insertion point in a given cell - Selection methods used from an insertion point are pretty efficient since no selecting actually gets done. But as you point out, even putting the insertion point in the cell isn't necessary...

    Gary

  6. #6
    New Lounger
    Join Date
    Mar 2002
    Location
    Sydney Australia
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Evaluate paragraphs in table cell (Word 2000)

    Thanks for that Jefferson

    I haven't had time to try it yet but I am sure it's the go.

    I do appreciate your response.

    PeteF

    (I used to be PeterF, but the system seems to have forgotten about me and no longer lets me logon under that name)

  7. #7
    New Lounger
    Join Date
    Mar 2002
    Location
    Sydney Australia
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Evaluate paragraphs in table cell (Word 2000)

    My thanks also to Gary and Stuart for their further refinements and related information.

    PeteF

  8. #8
    New Lounger
    Join Date
    Mar 2002
    Location
    Sydney Australia
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Evaluate paragraphs in table cell (Word 2000)

    As I like to proceed one step at a time, I used Gary's enhancement of Jefferson's approach with success:

    Dim CurPara As Paragraph

    For Each CurPara In Selection.Cells(1).Range.Paragraphs

    Select Case CurPara.Style()

    Case "Body Num"
    'do something...

    Case Else
    'do something else...

    End Select

    Next


    Thank you Stuart for your contribution re Range. I hope to explore your suggestion when I have the time.

    Thank you all for sharing your knowledge.

    PeteF

Posting Permissions

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