How to find a paragraph style in a Wd 2003 table

S

Steven Lee

Hi,

We have a legacy template (Word 2000) that uses paragraph styles in tables
(as that was the only way you could have table styles in 2000.). We also
have code that processes documents and looks for styles. In this case the
style is TFN (Table Footnote). If there is text w/i the cell tagged as TFN
then Selection.Find.Style = "TFN" will find the cell. However, if the celll
is empty (but the end of cell marker is tagged as "TFN") then selection.find
will not find the para/cell.

Is there any way to find "empty" paragraphs w/i tables using selection.find?

I can use:

Dim tblRng As Range
Dim tbl As Table
Dim para As Paragraph

For Each tbl In ActiveDocument.Tables
Set tblRng = tbl.Range
For Each para In tblRng.Paragraphs
If para.Style = "TFN" Then
para.Range.Select
MsgBox para.Style
End If
Next para
Next tbl

But this is rather more complicated than simply running a selection.find on
the "TFN" style. I'm trying to avoid having to hunt through several hundred
macros to replace all of our legacy code.

Thanks in advance!

Steve
 
G

Greg Maxey

Maybe something like:

Sub ScratchMacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Tables(1).Range
With oRng.Find
.Style = "TFN"
While .Execute
oRng.Cells(1).Select
oRng.Move wdCell, 1
If Selection.Range.End + 1 = ActiveDocument.Tables(1).Range.End
Then
Exit Sub
End If
Wend
End With
End Sub
 
S

Steven Lee

Thanks for the effort Greg. Unfortuantely your suggestion doesn't find the
empty cell I'm looking for, so it ends up selecting the first cell in the
table.


--
Steven Lee
Vaporloop Technology Solutions


Greg Maxey said:
Maybe something like:

Sub ScratchMacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Tables(1).Range
With oRng.Find
.Style = "TFN"
While .Execute
oRng.Cells(1).Select
oRng.Move wdCell, 1
If Selection.Range.End + 1 = ActiveDocument.Tables(1).Range.End
Then
Exit Sub
End If
Wend
End With
End Sub
 
G

Greg Maxey

Steven,

Yes I see what you mean. When I ran that snipet of code I have some
cells with TFN and text and some with just TFN.

Actually in a table with a single TFN formatted empty cell the style
is found. .Found returns true, but the range is not redefined to the
empty cell. I don't have a solution.
 
S

Steven Lee

Thanks for looking at this, Greg. I can't wait until we try to port this to
office 2007!

Best,
Steve
 

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