我可以使用 VBA 在 microsoft word 中选择一组表格进行格式化吗? [英] Can I select a group of tables to format in microsoft word using VBA?

查看:36
本文介绍了我可以使用 VBA 在 microsoft word 中选择一组表格进行格式化吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来快速格式化文档中的表格组.不幸的是,我不能只格式化所有表格,因为我必须保留一些未修改的内容(通常在附录中,但有时在开头).

I'm looking for a way to quickly format groups of tables in documents. Unfortunately I can't just format all tables as I have to leave some unmodified (usually in the appendices, but sometimes at the beginning).

到目前为止,我可以将所有表格从表 4 格式化到最后.例如,我不知道如何选择表 4 到 78.我还需要所有单元格在中间垂直定向.我花了很多时间来格式化每个单独的表格,因此非常感谢任何帮助.

What I have so far will allow me to format all tables from Table 4 to the end. I can't figure out how to select tables 4 through 78 for example. I also need all of the cells to be vertically oriented in the middle. I've spent an ungodly amount of my life formatting each individual table, so any help would be GREATLY APPRECIATED.

Sub FormatTables()

Dim TableIndex As Long
Dim Mytable As Table

For TableIndex = 4 To ActiveDocument.tables.Count
    Set Mytable = ActiveDocument.tables(TableIndex)
    With Mytable
        .Range.Style = ActiveDocument.Styles("TableText Arial 9")
        .PreferredWidthType = wdPreferredWidthPercent
        .PreferredWidth = 100
        .Rows.Alignment = wdAlignRowCenter
        .Rows.Height = InchesToPoints(0)
        .TopPadding = InchesToPoints(0)
        .BottomPadding = InchesToPoints(0)
        .LeftPadding = InchesToPoints(0.08)
        .RightPadding = InchesToPoints(0.08)
        .Spacing = 0
        .AllowPageBreaks = True
        .AutoFitBehavior (wdAutoFitWindow)
    End With
Next TableIndex

End Sub

推荐答案

例如:

Sub FormatTables()
Application.ScreenUpdating = False
Dim TableIndex As Long
For TableIndex = 4 To 78
  With ActiveDocument.Tables(TableIndex)
    .Range.Style = "TableText Arial 9"
    .PreferredWidthType = wdPreferredWidthPercent
    .PreferredWidth = 100
    .Rows.Alignment = wdAlignRowCenter
    'Format the paragraphs centrally as well
    '.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
    .Rows.Height = 0
    .TopPadding = 0
    .BottomPadding = 0
    .LeftPadding = InchesToPoints(0.08)
    .RightPadding = InchesToPoints(0.08)
    .Spacing = 0
    .AllowPageBreaks = True
    .AutoFitBehavior (wdAutoFitWindow)
    End With
Next TableIndex
Application.ScreenUpdating = True
End Sub

这篇关于我可以使用 VBA 在 microsoft word 中选择一组表格进行格式化吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆