vba 使用 Word 宏选择表格中的所有表格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11981981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 17:19:21  来源:igfitidea点击:

Select a all tables within table using Word Macro

vbams-wordword-vba

提问by nicemanda

I have these documents that I get regularly that I have to format and all the data is stored within tables that reside inside larger tables for layout purposes.

我有这些我经常收到的文档,我必须对其进行格式化,并且所有数据都存储在位于较大表格内的表格中,以便进行布局。

I'd like to style the column widths of the tables within tables if it's possible with a macro?

如果可以使用宏,我想为表格中表格的列宽设置样式?

回答by Olle Sj?gren

You can reference the nested tables directly. With the following command you get the number of tables contained in the first table in the document.

您可以直接引用嵌套表。使用以下命令,您可以获得文档中第一个表中包含的表数。

Debug.Print ThisDocument.Tables(1).Tables.Count

You can then loop through them and format them as desired:

然后,您可以遍历它们并根据需要格式化它们:

Dim oTable as Table

For Each oTable in ThisDocument.Tables(1).Tables

    'Do something with oTable - like
    'setting the width of the first column
    oTable.Columns(1).Width = 60

Next

Don't forget to check to see that there are tables in the document first. :)

不要忘记先检查文档中是否有表格。:)