Vba 编辑文本框中的特定行

Vba 编辑文本框中的特定行,vba,ms-word,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 =

我编写此宏是为了生成一个包含多行的文本框:

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


如何分别编辑每一行?

TextRange有一个段落集合。您可以循环或单独处理每个项目。比如说

Dim bxRange As Word.Range
Set bxRange = Bix.TextFrame.TextRange
bxRange.Paragraphs(1).Range.Font.Size = 12
bxRange.Paragraphs(2).Range.Font.Size = 10
使用以下命令:

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

这是在低质量帖子队列中。为避免删除,您可能需要解释您的答案。@RohitGupta对于这种特殊情况,不需要解释。