宏代码批量处理表格数据

Sub 在所有表格右侧添加一列()
For Each aTable In ActiveDocument.Tables
If aTable.Columns.Count = 5 Then
aTable.Columns(aTable.Columns.Count).Select
Selection.InsertColumnsRight
End If
Next aTable
End Sub

Sub 所有表格左对齐()
For i = 1 To ActiveDocument.Tables.Count

ActiveDocument.Tables(i).AutoFitBehavior (wdAutoFitContent) '根据内容自动调整表格

ActiveDocument.Tables(i).AutoFitBehavior (wdAutoFitWindow) '根据窗口自动调整表格

ActiveDocument.Tables(i).Range.ParagraphFormat.Alignment = wdAlignParagraphLeft

ActiveDocument.Tables(i).Range.ParagraphFormat.Alignment = wdCellAlignVerticalLeft

Next i
End Sub

Sub 设置表格宽度()
For Each aTable In ActiveDocument.Tables
If aTable.Columns.Count = 6 Then
aTable.Columns(1).Width = 30
aTable.Columns(6).Width = 50
End If
Next aTable
End Sub

Sub 第一行第六列属性列赋值()
For Each aTable In ActiveDocument.Tables
If aTable.Columns.Count = 6 Then
aTable.Cell(1, 6).Range.InsertAfter "类型"
End If
Next aTable
End Sub


Sub 每行第六列赋值String()
For Each aTable In ActiveDocument.Tables
If aTable.Columns.Count = 6 Then

For i = 2 To aTable.Rows.Count

aTable.Cell(i, 6).Range.InsertAfter "String"

Next i

End If
Next aTable
End Sub

原文地址:https://www.cnblogs.com/pjh7/p/14334783.html