O
Ogier
Hi out there!
With the macro below I wish to accomplish the following:
1) At the insertion point, insert a carriage return
2) Somehow mark the current position
3) Insert some formatted text
4) Select the text from the marked position to the end of the insertion
5) Indent the selected text at both margins
6) Insert a carriage return
In other words: Indent a piece of inserted text without affecting the layout
of previous or following text. Here is my macro:
Sub Makro1()
' Purpose: Write some formatted text and indent it from both left and
right
Dim i As Integer
Dim SStart As Integer
Dim SEnd As Integer
Dim Range As Object
Selection.Collapse wdCollapseStart
Selection.InsertParagraph
SStart = Selection.Start
' Insert some formatted text
Selection.Font.Bold = wdToggle
Selection.TypeText "Title in bold"
Selection.Font.Bold = wdToggle
Selection.TypeText vbCr
For i = 1 To 10
Selection.TypeText Text:="Here is some dummy text. "
Next i
SEnd = Selection.Start
' Set range
ActiveDocument.Range SStart, SEnd
' Indent text in range
With ActiveDocument.Range.ParagraphFormat
.LeftIndent = CentimetersToPoints(2)
.RightIndent = CentimetersToPoints(2)
.SpaceBefore = 6
.SpaceAfter = 6
End With
Selection.InsertParagraph
End Sub
The inserted text is indeed indented from both sides, but so is the
neighboring text! Somehow the selection is not done correctly.
Any suggestions would be helpful!
Best wishes
Holger Nielsen
With the macro below I wish to accomplish the following:
1) At the insertion point, insert a carriage return
2) Somehow mark the current position
3) Insert some formatted text
4) Select the text from the marked position to the end of the insertion
5) Indent the selected text at both margins
6) Insert a carriage return
In other words: Indent a piece of inserted text without affecting the layout
of previous or following text. Here is my macro:
Sub Makro1()
' Purpose: Write some formatted text and indent it from both left and
right
Dim i As Integer
Dim SStart As Integer
Dim SEnd As Integer
Dim Range As Object
Selection.Collapse wdCollapseStart
Selection.InsertParagraph
SStart = Selection.Start
' Insert some formatted text
Selection.Font.Bold = wdToggle
Selection.TypeText "Title in bold"
Selection.Font.Bold = wdToggle
Selection.TypeText vbCr
For i = 1 To 10
Selection.TypeText Text:="Here is some dummy text. "
Next i
SEnd = Selection.Start
' Set range
ActiveDocument.Range SStart, SEnd
' Indent text in range
With ActiveDocument.Range.ParagraphFormat
.LeftIndent = CentimetersToPoints(2)
.RightIndent = CentimetersToPoints(2)
.SpaceBefore = 6
.SpaceAfter = 6
End With
Selection.InsertParagraph
End Sub
The inserted text is indeed indented from both sides, but so is the
neighboring text! Somehow the selection is not done correctly.
Any suggestions would be helpful!
Best wishes
Holger Nielsen