Moving the insertion point back to end of previous paragraph

J

John Wirt

What command should I use to move the insertion point back to the end of the
previous paragraph.

Here is the code.

For Each aPara In rng.Paragraphs
aPara.Range.Select
If Selection.Characters.Count > 3 Then
Selection.Collapse (wdCollapseEnd)
Selection.Moveleft(wdChar,1) <===??
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldSequence,
Text:="Sequence"
End If
Next aPara


John Wir
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi John,

I assume that you want to insert a sequential number before each paragraph
in the range, possibly followed by a tab? If that's the case, use:

Dim aPara As Paragraph, rng As Range, rnge As Range
Set rng = Selection.Range
For Each aPara In rng.Paragraphs
If Len(aPara.Range) > 3 Then
Set rnge = aPara.Range
rnge.InsertBefore vbTab
rnge.Collapse wdCollapseStart
ActiveDocument.Fields.Add Range:=rnge, Type:=wdFieldSequence,
Text:="Sequence"
End If
Next aPara


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
J

John Wirt

Thanks, Doug.

I would like to change the format of the paragrpah numbering so that the
numbering aapears as (#n).

I got this far with the code you uploaded on these pages:

Set rng = Selection.Range
For Each aPara In rng.Paragraphs
If Len(aPara.Range) > 3 Then
Set rnge = aPara.Range
rnge.InsertBefore ")" & vbTab
rnge.Collapse wdCollapseStart
ActiveDocument.Fields.Add Range:=rnge, Type:=wdFieldSequence, _
Text:="Sequence"
End If
Next aPara

How can I move the insertion point to the left of the inserted Sequence
Field and insert the characters "(#" ?

Thanks.

John


"Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS"
news:%[email protected]...
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi John,

Use

Dim aPara As Paragraph, rng As Range, rnge As Range
Set rng = Selection.Range
For Each aPara In rng.Paragraphs
If Len(aPara.Range) > 3 Then
Set rnge = aPara.Range
rnge.InsertBefore ")" & vbTab
rnge.Collapse wdCollapseStart
ActiveDocument.Fields.Add Range:=rnge, Type:=wdFieldSequence,
Text:="Sequence"
rnge.InsertBefore "(#"
End If
Next aPara


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi John,

After the ) and the tab are inserted at the beginning of the range, they
become part of the range so the range is collapsed to its start. When the
field is added, it is added into the range. The (# is then inserted before
the range. It is not necessary to collapse the range to its start to insert
something before it. But if it is not collapsed to its start when the field
is added, the field will replace anything that is then in the range.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
J

John Wirt

When the field code is inserted, rnge expands to include it? Is this a
characteristic of the Add method? After the collapse, rnge is the insertion
code. Right?

Or, after inserting the field, does Add move the insertion point before it,
still defining the insertion point to be rnge?

John

"Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top