Is previous line in a table?

  • Thread starter Victor Boris Arnold
  • Start date
V

Victor Boris Arnold

I'm trying to code some logic to determine whether the
line above the current selection is a table row. I've been
able to do so using the GoToPrevious method with the
wdLine option for the selection, then using the
wdWithInTable option of the Information property, but I'd
like to be able to use a range instead so I don't have to
move the selection. When I try the GoToPrevious with the
Selection.Range, however, it doesn't work. It must not
recognize the new range.

Also, I'd be interested to know if anyone has a better way
to do determine whether the preceding line is in a table.
 
P

Peter Hewett

Hi Victor Boris Arnold

You can try this though it may not do exactly what you require at the moment:

Public Function IsLineAboveTableRow() As Boolean
Dim rngPrevious As Word.Range

Set rngPrevious = Selection.Range

' We can't do test if this is the first paragraph of the document
rngPrevious.Start = ActiveDocument.Content.Start
If rngPrevious.Paragraphs.Count > 1 Then

' Map range to previous paragraph
Set rngPrevious = Selection.Range
rngPrevious.Move wdParagraph, -1
IsLineAboveTableRow = rngPrevious.Information(wdWithInTable)
End If
End Function

The problem with it is that Table *always* terminates with a Paragraph mark, so unless you
actually position the insertion point just before the Paragraph mark it may not do what
you want. If this is the case adapt the logic to use 2 paragraphs before the current
paragraph.

HTH + Cheers - Peter
 
A

Andrew Savikas

Hi Victor

Since a "line" on one machine may not be the same "line" on another, I'm assuming you want to know if the previous paragraph is in a table. Try the following

MsgBox Selection.Range.Previous(wdParagraph).Tables.Coun

If the value is not 0, then the previous paragraph is in a table

HTH
Andrew Savikas

----- Victor Boris Arnold wrote: ----

I'm trying to code some logic to determine whether the
line above the current selection is a table row. I've been
able to do so using the GoToPrevious method with the
wdLine option for the selection, then using the
wdWithInTable option of the Information property, but I'd
like to be able to use a range instead so I don't have to
move the selection. When I try the GoToPrevious with the
Selection.Range, however, it doesn't work. It must not
recognize the new range

Also, I'd be interested to know if anyone has a better way
to do determine whether the preceding line is in a table
 
A

Andrew Savikas

You could also use

Selection.Range.Previous(wdParagraph).Information(wdWithInTable

-- Andre
----- Andrew Savikas wrote: ----

Hi Victor

Since a "line" on one machine may not be the same "line" on another, I'm assuming you want to know if the previous paragraph is in a table. Try the following

MsgBox Selection.Range.Previous(wdParagraph).Tables.Coun

If the value is not 0, then the previous paragraph is in a table

HTH
Andrew Savikas

----- Victor Boris Arnold wrote: ----

I'm trying to code some logic to determine whether the
line above the current selection is a table row. I've been
able to do so using the GoToPrevious method with the
wdLine option for the selection, then using the
wdWithInTable option of the Information property, but I'd
like to be able to use a range instead so I don't have to
move the selection. When I try the GoToPrevious with the
Selection.Range, however, it doesn't work. It must not
recognize the new range

Also, I'd be interested to know if anyone has a better way
to do determine whether the preceding line is in a table
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top