修改文本框中的特定行

时间:2015-12-25 21:46:58

标签: vba ms-word

我写了这个宏来生成一个包含多行的文本框:

Sub multipleLineTextBox()

    Dim Box As Shape
    Set Box = ActiveDocument.Shapes.AddTextbox( _
        Orientation:=msoTextOrientationHorizontal, _
        Left:=50, Top:=50, Width:=200, Height:=200)

        Box.Line.Style = msoLineThinThin
        Box.Line.Weight = 6
        Box.TextFrame.TextRange.Text = "first line" & vbCrLf & "second line"
        Box.TextFrame.TextRange.Font.Size = 20

End Sub

最后一行将文本框中的所有文本编辑为大小为20。

如何单独编辑每一行?

2 个答案:

答案 0 :(得分:1)

TextRange有一个Paragraphs集合。您可以循环或单独使用每个项目。例如

Dim bxRange As Word.Range
Set bxRange = Bix.TextFrame.TextRange
bxRange.Paragraphs(1).Range.Font.Size = 12
bxRange.Paragraphs(2).Range.Font.Size = 10

答案 1 :(得分:0)

使用此:

Sub multipleLineTextBox()
    Dim Box As Shape
    Set Box = ActiveDocument.Shapes.AddTextbox( _
        Orientation:=msoTextOrientationHorizontal, _
        Left:=50, Top:=50, Width:=200, Height:=200)
        With Box
            .Line.Style = msoLineThinThin
            .Line.Weight = 6
            .TextFrame.TextRange.Text = "first line" & vbCrLf & "second line"
            .TextFrame.TextRange.Paragraphs(2).Range.Font.Size = 20
        End with
End Sub