简体   繁体   English

如何使用vba宏更改word文档中所有表格的字体大小

[英]How to change the font size of all tables in a word document using a vba macro

I have a word document with a lot of tables.我有一个包含很多表格的 word 文档。 I would like a macro which changes the fonts size of all tables to 10, autofits each table to the window and distributes the columns evenly.我想要一个宏,它将所有表格的字体大小更改为 10,将每个表格自动调整到窗口并均匀分布列。 I can accomplish the last two goals using the below code, but not sure how to change the font size.我可以使用下面的代码完成最后两个目标,但不确定如何更改字体大小。 Any help would be greatly appreciated.任何帮助将不胜感激。

Sub changetables()
Dim tbl As Table
For Each tbl In ActiveDocument.Tables
    tbl.AutoFitBehavior wdAutoFitWindow
    tbl.Columns.DistributeWidth

Next

End Sub

For your exact code use对于您的确切代码使用

   tbl.Range.Font.Size = 12

I have retyped a few things to show better naming and spacing etc.我重新输入了一些内容以显示更好的命名和间距等。

 Sub changetables()

      Dim CurrentTable As Table

      For Each CurrentTable In ActiveDocument.Tables

           With CurrentTable

                .AutoFitBehavior wdAutoFitWindow
                .Columns.DistributeWidth
                .Range.Font.Size = 12
           End With

      Next CurrentTable

 End Sub

Just change .size to .name, as in tbl.Range.Font.Name = "Calibri"只需将 .size 更改为 .name,如 tbl.Range.Font.Name = "Calibri"

This should also work for whatever font name you wish to use by replacing Calibri within the double quotes to your desired font name.这也适用于您希望使用的任何字体名称,方法是将双引号内的 Calibri 替换为您想要的字体名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM