2017-02-19 72 views
1

我想创建一个循环遍历表中的每一行并删除底部边框的宏。字宏从每一行中删除底部边框

到目前为止,我有:

Sub Remove() 

Set myTable = Selection.Tables(1) 
    With myTable.Borders 

Selection.Cells.Borders(wdBorderBottom) = wdLineStyleNone 

    End With 

End Sub 

但它仅适用于一列,它必须选择。 如何将其应用于所有行?

回答

0

您需要遍历表中的所有行,并将每行下边框格式化为wdLineStyleNone

代码

尝试下面的代码:

Sub Remove() 

Dim myTable As Table 
Dim r As Variant 

Set myTable = ThisDocument.Tables(1) 

For Each r In myTable.Rows ' <-- loop through all rows in table 
    r.Borders(wdBorderBottom) = wdLineStyleNone 
Next r 

End Sub 
+0

感谢您的答复!它看起来不错,但是当我尝试它,则显示 消息: 运行时错误“5941”: 集合的请求的成员不存在 和“设置为myTable = ThisDocument.Tables(1) “突出显示。 脚本应该先选择表格吗? 我试着添加“ActiveDocument.Tables(1).Select”,但它没有帮助。 – LeFunk

+0

@LeFunk没有必要选择一个表格,你的Word文档中是否创建了1个表格?代码在哪里? –

+0

我有一个只有一个表的文档,它有一列。 代码在通常的宏窗口中(如果这是正确的术语)。 – LeFunk