2013-02-08 86 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