【问题标题】:Autofit table contents but with max table width自动调整表格内容,但具有最大表格宽度
【发布时间】:2016-12-06 03:20:23
【问题描述】:

我正在尝试通过 vba 自动调整 word 中的表格内容,但是在使用自动调整时,列会缩小到正确的大小,但表格的宽度也会缩小。如何将表格宽度保持在最大值?

代码:

With tableEmployees
    .AllowAutoFit = True
    .AutoFitBehavior wdAutoFitWindow
    .Columns(1).AutoFit
    .Columns(2).AutoFit
    .Columns(3).AutoFit
    .Columns(4).AutoFit
End With

表结构:

id |   name   |   phone   |         email    |
 1 | john doe | 555-5555  | john.doe@someadd
                                    ress.com

当我自动调整列以使电子邮件地址出现在一行时,表格宽度会缩小。我希望表格占据页面上的空白空间,以便填满右侧。我在这个上面的表格是全宽的,我希望这个在它下面是全宽的,但是所有单元格内容都在一行上可见,因为它们有空间。

【问题讨论】:

    标签: vba ms-word


    【解决方案1】:

    这样的事情对我有用:

    With tableEmployees
      .AllowAutoFit = True
      .AutoFitBehavior wdAutoFitContent
      .Columns.AutoFit
      .AutoFitBehavior wdAutoFitWindow
      .Columns.AutoFit
    End With
    

    自动调整内容大小,使列相对于彼此合理。

    窗口是边距和列边框之间的宽度,因此自动调整到窗口会将表格调整为边距内的页面宽度,并保留自动调整到内容设置的比例。

    【讨论】:

      【解决方案2】:

      好的,我能够通过以下修改解决我自己的问题:

      With tableEmployees
          .PreferredWidthType = wdPreferredWidthPercent
          .PreferredWidth = 100
          .Columns(1).PreferredWidth = 15
          .Columns(2).PreferredWidth = 25
          .Columns(3).PreferredWidth = 20
          .Columns(4).PreferredWidth = 40
      End With
      

      效果很好!

      【讨论】:

        猜你喜欢
        • 2013-06-23
        • 2014-04-17
        • 2014-03-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-01
        • 1970-01-01
        相关资源
        最近更新 更多