我有一个word文档,它是从我的程序生成的,目前有一个用新行代替<BR/>
标记的宏。这表示表中新部分的开始,因此我还想在<BR/>
标记出现的行的顶部添加边框。我目前的代码是:
With ActiveDocument.Content.Find
.Text = "<BR/>"
.Forward = True
While .Execute
.Parent.Text = Chr(10)
.Parent.Collapse wdCollapseEnd
Wend
End With
如何在<BR/>
出现的表格中获取整行,然后为其添加边框?
到目前为止,我的尝试是在崩溃后添加while循环结束:
With .Parent.Row.Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
但这没有做任何事情(也没有错误)。我不认为我正确地抓住了行,但我找不到任何其他方法。感谢。
编辑:
我现在想也许我应该在换行符之前单独检查一下。因此,添加for循环以遍历所有表行,检查是否存在<BR/>
以及是否在行的顶部添加了边框。
我不习惯vba,通常使用excel所以想想我可能会混合两者。这是我到目前为止所得到的:
Dim oTbl As Table
Set oTbl = ActiveDocument.Tables(1)
For Each oRow In oTbl.Rows
If InStr(1, oRow.Cell(1, 1), "<BR/>", vbBinaryCompare) > 0 Then
oRow.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
End If
Next
答案 0 :(得分:0)
好的,我使用for循环方式工作了。我的最终代码是:
Dim oTbl As Table
Dim oRow As Row
For Each oTbl In ActiveDocument.Tables
For Each oRow In oTbl.Rows
If InStr(1, oRow.Cells(1).Range.Text, "<BR/>", vbBinaryCompare) > 0 Then
oRow.Borders(wdBorderTop).LineStyle = wdLineStyleSingle
End If
Next
Next
因此,这会遍历文档中的所有表格,然后每个表格中的所有行在每个行的上方添加一条边框线,其第一个单元格中包含<BR/>
标记(表示新的部分)。我在代码的下一部分之前完成所有这些操作,用新行字符替换<BR/>
标记。
希望这有助于将来。