处理当前文档所有表格的 VBA 代码请在 Word 中按下 Alt + F11 打开 VBA 编辑器,插入一个新模块,然后粘贴以下代码:
Sub ProcessAllTablesInCurrentDoc()
Dim doc As Document
Dim tbl As Table
Dim tableCount As Long
' 获取当前活动文档
Set doc = ActiveDocument
tableCount = doc.Tables.Count
' 检查文档中是否存在表格
If tableCount > 0 Then
' 循环处理文档中的每一个表格
For Each tbl In doc.Tables
With tbl.Borders
' 设置内部和外部框线为单实线
.InsideLineStyle = wdLineStyleSingle
.OutsideLineStyle = wdLineStyleSingle
' 设置线条粗细(wdLineWidth050pt 为 0.5磅,可根据需要调整)
.InsideLineWidth = wdLineWidth050pt
.OutsideLineWidth = wdLineWidth050pt
' 设置线条颜色(自动/黑色)
.InsideColorIndex = wdAuto
.OutsideColorIndex = wdAuto
End With
Next tbl
MsgBox "当前文档中的 " & tableCount & " 个表格已全部加好框线!", vbInformation, "完成"
Else
MsgBox "当前文档中没有找到任何表格!", vbExclamation, "提示"
End If
End Sub
希望能帮到你 |