2017-02-19 38 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