msword-vba应用样式



我有一段代码,可以将excel单元格值插入word文档:

    Set wrdRange = wrdDoc.Range
    With wrdRange
        .Collapse Direction:=wdCollapseEnd
         .InsertParagraphAfter
         xText = Rng.Cells(i + 1, 1).Value
         .InsertAfter xText
        .Collapse Direction:=wdCollapseEnd
    End With

我需要用H1设计xText的样式,但没有得到。
xText可能包含许多单词。

提前谢谢。

试试这个。

Set wrdRange = wrdDoc.Range
With wrdRange
    .Collapse Direction:=wdCollapseEnd
    .InsertParagraphAfter
    xText = Rng.Cells(i + 1, 1).Value
    .InsertAfter xText
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.MoveRight Unit:=wdCharacter, Count:=Len(xText), Extend:=wdExtend
    Selection.Style = ActiveDocument.Styles("Heading 1")
    .Collapse Direction:=wdCollapseEnd
End With

最新更新