MK_
12-04-2010, 06:13 AM
Hi all,
I wish to create a textbox (shape) with more than one paragraph with diferent formats (alignment, font, etc).
I´ve tried to use TextFrame.TextRange.InsertParagraphBefore and TextFrame.TextRange.InsertParagraphAfter to achieve it, with no results.
Each time TextFrame.TextRange.Text is used the whole text inside the textbox is replaced. No idea how to proceed.
I´m using MS Word 2003.
Sample code:
Public Sub TxBox()
Dim oTextBox As Shape
Set oTextBox = ActiveDocument.Shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=0, _
Top:=0, _
Width:=InchesToPoints(3), _
Height:=InchesToPoints(1), _
Anchor:=ActiveDocument.Paragraphs(1).Range)
With oTextBox
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Left = InchesToPoints(3)
.Top = InchesToPoints(4)
.TextFrame.TextRange.Text = "Paragraph one"
With .TextFrame.TextRange.ParagraphFormat
.Alignment = wdAlignParagraphCenter
End With
'
' Here should come the second paragraph
'
.TextFrame.MarginTop = 0
.TextFrame.MarginLeft = 0
.Line.Visible = msoTrue
.Fill.Visible = msoFalse
End With
End Sub
Thanks in advance.
I wish to create a textbox (shape) with more than one paragraph with diferent formats (alignment, font, etc).
I´ve tried to use TextFrame.TextRange.InsertParagraphBefore and TextFrame.TextRange.InsertParagraphAfter to achieve it, with no results.
Each time TextFrame.TextRange.Text is used the whole text inside the textbox is replaced. No idea how to proceed.
I´m using MS Word 2003.
Sample code:
Public Sub TxBox()
Dim oTextBox As Shape
Set oTextBox = ActiveDocument.Shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=0, _
Top:=0, _
Width:=InchesToPoints(3), _
Height:=InchesToPoints(1), _
Anchor:=ActiveDocument.Paragraphs(1).Range)
With oTextBox
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Left = InchesToPoints(3)
.Top = InchesToPoints(4)
.TextFrame.TextRange.Text = "Paragraph one"
With .TextFrame.TextRange.ParagraphFormat
.Alignment = wdAlignParagraphCenter
End With
'
' Here should come the second paragraph
'
.TextFrame.MarginTop = 0
.TextFrame.MarginLeft = 0
.Line.Visible = msoTrue
.Fill.Visible = msoFalse
End With
End Sub
Thanks in advance.