[英]vba apply style
I have this piece of code that inserts an excel cell value into a word document: 我有这段代码,将一个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
I need to style xText with H1, but don't get it. 我需要用H1设置xText的样式,但不要理解 。
xText may contain many word. xText可能包含许多单词。
Thank you in advance. 先感谢您。
Try this. 尝试这个。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.