预格式化字符串

时间:2018-05-13 07:11:08

标签: vba ms-word word-vba

在处理下面的宏来填充MS字表时,我有一个单元格,有两个语句,一个是粗体文本而另一个不是,下面是我接近它的方式。我确信实现快速格式化的字符串插入有更智能,更直接的方式。另外,下面的实现没有任何想法?

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 个答案:

答案 0 :(得分:0)

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