代码之家  ›  专栏  ›  技术社区  ›  Walid Abdelal

预格式化字符串的在线插入

  •  1
  • Walid Abdelal  · 技术社区  · 6 年前

    在使用下面的宏填充MS word表格时,我脑海中有一个单元格,其中有两条语句,一条是粗体文本,另一条不是,下面是我处理它的方式。我相信有一种更智能、更在线的方式来实现快速格式化的字符串插入。而且,下面的实现没有任何效果?

    For n = 1 To nCount
        With oTable.Rows(n + 1)
            'Page number
            .Cells(1).Range.Text = _
                oDoc.Comments(n).Scope.Information(wdActiveEndPageNumber)
            .
            .
            .
            .Cells(3).Range.Text = "First Statement: "
            .Cells(3).Range.Select
            With .Cells(3).Range
                .Bold = True
            End With
            .Cells(3).Range.Bold = False
            .Cells(3).Range.InsertAfter ("Second Statement")
        End With
    Next n
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   macropod    6 年前
    Dim Rng As Range
    For n = 1 To nCount
        With oTable.Rows(n + 1)
            'Page number
            .Cells(1).Range.Text = _
                oDoc.Comments(n).Scope.Information(wdActiveEndPageNumber)
            '
            '
    
        Set Rng = .Cells(3).Range
        With Rng
          .End = .End - 1
          .Text = "First Statement: "
          .Font.Bold = True
          .Collapse wdCollapseEnd
          .Text = "Second Statement"
          .Font.Bold = False
        End With
    Next n