Sub 全选所有表格()
Dim t As Table
an = MsgBox("即将选择选区内所有表格,若无选区,则选择全文表格。", vbYesNo, "reboot提醒您!")
If an - 6 Then Exit Sub
Set rg = IIf(Selection.Type = wdSelectionIP, ActiveDocument.Content, Selection.Range)
ActiveDocument.DeleteAllEditableRanges wdEditorEveryone
For Each t In rg.Tablest.Range.Editors.Add wdEditorEveryone
Next
ActiveDocument.SelectAllEditableRanges wdEditorEveryone
ActiveDocument.DeleteAllEditableRanges wdEditorEveryone
End SubSub 全选所有表格首行()
Dim t As Table
Dim firstRow As Row
an = MsgBox("即将选择选区内所有表格的首行,若无选区,则选择全文表格的首行。", vbYesNo, "reboot提醒您!")
If an - 6 Then Exit Sub
Set rg = IIf(Selection.Type = wdSelectionIP, ActiveDocument.Content, Selection.Range)
ActiveDocument.DeleteAllEditableRanges wdEditorEveryone
For Each t In rg.TablesIf t.Rows.Count >= 1 ThenSet firstRow = t.Rows(1)firstRow.Range.Editors.Add wdEditorEveryoneEnd If
Next
ActiveDocument.SelectAllEditableRanges wdEditorEveryone
ActiveDocument.DeleteAllEditableRanges wdEditorEveryone
End SubSub 全选所有表格_调整格式()Dim t As TableDim an As IntegerDim rg As RangeDim tableCount As IntegerDim cell As cell' 确认提示an = MsgBox("即将格式化选区内所有表格,若无选区,则格式化全文表格。" & vbCrLf & _"操作包括:" & vbCrLf & _"1. 根据窗口调整宽度" & vbCrLf & _"2. 平均分布各行" & vbCrLf & _"3. 设置行高为1厘米" & vbCrLf & _"4. 设置单元格文本左对齐", vbYesNo, "reboot提醒您!")If an <> vbYes Then Exit Sub' 确定操作范围Set rg = IIf(Selection.Type = wdSelectionIP, ActiveDocument.Content, Selection.Range)tableCount = 0' 直接遍历表格并应用格式Application.ScreenUpdating = FalseFor Each t In rg.Tables' 应用表格级格式t.AutoFitBehavior wdAutoFitWindowt.Rows.DistributeHeightt.Rows.Height = CentimetersToPoints(1)t.Rows.HeightRule = wdRowHeightExactly' 遍历单元格设置对齐方式For Each cell In t.Range.Cellscell.VerticalAlignment = wdCellAlignVerticalCenter ' 垂直居中cell.Range.ParagraphFormat.Alignment = wdAlignParagraphLeft ' 水平左对齐Next celltableCount = tableCount + 1Next tApplication.ScreenUpdating = True' 提示结果If tableCount > 0 ThenMsgBox "已成功格式化 " & tableCount & " 个表格!", vbInformationElseMsgBox "未找到可格式化的表格!", vbExclamationEnd If
End Sub