tetsting a document for tables

M

macroapa

Hi,

I want to create a function that returns a boolean if the document
contains a table (or number of tables) *where* any part of the table
has a borded (of any type). A document with borderless tables should
return false.

I reckon I can probably get some code to test if there are any tables,
but don't really know where to begin to test each table found to see
if it has any bordering on it.

Any pointers appreciated.

Thanks.
 
M

macroapa

Okay, i'm thinking something like below, but obviosuly having a test
for each border type:

Function testtables() As Boolean

Dim x As Integer
Dim xx As Integer
Dim y As Boolean
x = ActiveDocument.Tables.Count
y = False

Do While x < xx
If ActiveDocument.Tables(x).Borders(wdBorderBottom) = True Then
y = True
End If
Loop

End Function
 
M

macroapa

Right, this i think is my final version. Any comments appreicated:

Function testtable() As Boolean

Dim x As Integer
Dim xx As Integer

xx = ActiveDocument.Tables.Count
testtable = False
x = 1

Do While x <= xx
If ActiveDocument.Tables(x).Borders(wdBorderBottom) = True _
Or ActiveDocument.Tables(x).Borders(wdBorderHorizontal) =
True _
Or ActiveDocument.Tables(x).Borders(wdBorderLeft) = True _
Or ActiveDocument.Tables(x).Borders(wdBorderRight) = True
_
Or ActiveDocument.Tables(x).Borders(wdBorderTop) = True _
Or ActiveDocument.Tables(x).Borders(wdBorderVertical) =
True _
Or ActiveDocument.Tables(x).Borders(wdBorderDiagonalDown)
= True _
Or ActiveDocument.Tables(x).Borders(wdBorderDiagonalUp) =
True Then
testtable = True
Exit Do
End If
x = x + 1
Loop

End Function
 
D

Doug Robbins - Word MVP

That will not get a border applied to just one cell.

Better to use

Dim Flag As Boolean
Dim i As Long, j As Long, n As Long
Dim acell As Cell
Flag = False
With ActiveDocument
For i = 1 To .Tables.Count
With .Tables(i)
For j = 1 To .Borders.Count
If .Borders(i).Visible = True Then
Flag = True
End If
Next j
For k = 1 To .Rows.Count
With .Rows(k)
For n = 1 To .Cells.Count
With .Cells(n)
For j = 1 To .Borders.Count
If .Borders(i).Visible = True Then
Flag = True
End If
Next j
End With
Next n
End With
Next k
End With
Next i
End With
MsgBox Flag

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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