如何使用 VBA 宏选择 Microsoft Word 文档中的每个表格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27552157/
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
How to select every table in a Microsoft Word document using VBA Macro
提问by Cellobin22
I am looking for a way (or decent introduction) into how to select every table in a Microsoft Word 2013 Document and autofit the contents. Each table is independent of one another and separated by text.
我正在寻找一种方法(或体面的介绍)来了解如何选择 Microsoft Word 2013 文档中的每个表格并自动调整内容。每个表格相互独立,并由文本分隔。
I have established the following code so far:
到目前为止,我已经建立了以下代码:
Sub autofit()
Selection.Tables(1).AutoFitBehavior (wdAutoFitContent)
End Sub
Which works for individual tables and every column in said table, I understand the format of the "for loop", but would like a nudge to how to transform my individual selection to the entire document.
这适用于单个表格和所述表格中的每一列,我了解“for 循环”的格式,但想了解如何将我的个人选择转换为整个文档。
This is my first post so apologies for any conventions I have missed.
这是我的第一篇文章,因此对于我错过的任何约定表示歉意。
回答by Alex K.
Its pretty trivial to loop them all;
将它们全部循环起来非常简单;
Dim t As Table
For Each t In ActiveDocument.Tables
t.AutoFitBehavior wdAutoFitContent
Next