2013-02-08 88 views
0

我有这样的一段代码,把一个Excel单元格值转换成word文档:VBA应用样式

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

我需要的款式XTEXT与H1,但不明白这一点。
xText可能包含许多单词。

预先感谢您。

回答

0

试试这个。

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 
+0

我试过你的建议,但如果运行时错误失败(选择不是支持者)。经过一番研究,我发现这样做的方式:随着wrdRange .Collapse方向:= wdCollapseEnd .InsertParagraphAfter XTEXT = Rng.Cells(我+ 1,1).value的 .InsertAfter XTEXT 则可对(2).Style =“Heading 1” .InsertParagraphAfter 。折叠方向:= wdCollapseEnd End With – 2013-02-14 16:07:21