【问题标题】:Macro for adding zeroes to the front of numbers in specific Word doc table columns用于在特定 Word 文档表格列中的数字前面添加零的宏
【发布时间】:2011-10-25 00:44:50
【问题描述】:

谁能提供任何 VBA 宏建议?

在 Word 文档表中,我只需将以下规则应用于第一列:

我需要在数字前面添加零 (0) 以使它们的总长度达到 8 个字符。所有数字都以一个或两个字母结尾,这将包含在 8 个字符的计数中。

例如:

2020A (5 characters) must read 0002020A (8 characters)
123456AB (8 characters) remains unchanged
765432X (7 characters) must read 0765432X (8 characters)

如何将其应用于 Word 文档中表的第一列中的每个字段?

【问题讨论】:

    标签: vba ms-word


    【解决方案1】:

    vbaexpress论坛上macropod提供的答案:

    Dim RngCel As Range, oCel As Cell, oTbl As Table 
    For Each oTbl In ActiveDocument.Tables 
        For Each oCel In oTbl.Columns(1).Cells 
            Set RngCel = oCel.Range 
            RngCel.End = RngCel.End - 1 
            While Len(RngCel.Text) < 8 
                RngCel.InsertBefore "0" 
            Wend 
        Next oCel 
    Next oTbl
    

    http://www.vbaexpress.com/forum/showthread.php?p=254288#post254288

    【讨论】:

      猜你喜欢
      • 2016-07-07
      • 2010-09-24
      • 1970-01-01
      • 1970-01-01
      • 2015-05-14
      • 1970-01-01
      • 1970-01-01
      • 2019-10-31
      • 1970-01-01
      相关资源
      最近更新 更多