美文网首页
BRword中表格格式统一调整

BRword中表格格式统一调整

作者: 吃夏天的薄荷 | 来源:发表于2020-08-27 09:55 被阅读0次

首先,一次性选中 word 中所有表格。利用宏选择所有表格。
首先,我们进入「开发工具」-「Visual Basic」将下列代码复制进去(该宏的主要作用是,可以让你一次选中文档中所有的表格)。然后,在「宏」中点击「运行」。

Sub SelectAllTables()
    Dim tempTable As Table    
    Application.ScreenUpdating = False    
    '判断文档是否被保护
    If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
        MsgBox "文档已保护,此时不能选中多个表格!"
        Exit Sub
    End If
    '删除所有可编辑的区域
    ActiveDocument.DeleteAllEditableRanges wdEditorEveryone
    '添加可编辑区域
    For Each tempTable In ActiveDocument.Tables
        tempTable.Range.Editors.Add wdEditorEveryone
    Next
    '选中所有可编辑区域
    ActiveDocument.SelectAllEditableRanges wdEditorEveryone
    '删除所有可编辑的区域
    ActiveDocument.DeleteAllEditableRanges wdEditorEveryone    
    Application.ScreenUpdating = True    
End Sub

设置表格样式“可研专用”为虚框1.5磅,居中。
其次,打开Alt + F11,打开宏编辑器,选择本文档,选择Open,代码如下:

Private Sub Document_Open()
Application.Browser.Target = wdBrowseTable
    For i = 1 To ActiveDocument.Tables.Count
    ActiveDocument.Tables(i).PreferredWidth = CentimetersToPoints(16)'表格宽度调整为16厘米   
    ActiveDocument.Tables(i).Style =“可研专用“
    ActiveDocument.Tables(i).AutoFitBehavior(wdAutoFitContent)'根据内容自动调整表格
    ActiveDocument.Tables(i).AutoFitBehavior(wdAutoFitWindow)'根据窗口自动调整表格
    ActiveDocument.Tables(i).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter'水平居中
    ActiveDocument.Tables(i).Range.ParagraphFormat.Alignment = wdCellAlignVerticalCenter'垂直居中
    ActiveDocument.Tables(i).Range.ParagraphFormat.CharacterUnitFirstLineIndent = 0'取消字符单位的首行缩进
    ActiveDocument.Tables(i) .Range.ParagraphFormat。FirstLineIndent = 0'取消首行缩进
   End Sub

相关文章

网友评论

      本文标题:BRword中表格格式统一调整

      本文链接:https://www.haomeiwen.com/subject/ietcsktx.html