Loop thru doc and stop @ SEQ field

J

jbc

Hi,

I have a document with SEQ fields. I'm working with a document that should
have SEQ fields when the style is Normal. Any other style and no SEQ number.
The SEQ field is always at the beginning of the paragraph.

This is what I would like to do:

If style not normal then

go to next paragraph


if normal

test if SEQ field @ left margin


if SEQ field already there go onto next paragraph

else add SEQ field

go to next paragraph and do all over again

I'm mainly having problems testing for the SEQ field

Thanks

jbc
 
G

Greg Maxey

jbc,

Maybe something like:

Sub Test()
Dim oPar As Paragraph
Dim oRng As Range
ActiveWindow.View.ShowFieldCodes = True
For Each oPar In ActiveDocument.Paragraphs
If oPar.Style = "Normal" Then
If Not Mid(oPar.Range.Text, 3, 3) = "SEQ" Then
Set oRng = oPar.Range.Duplicate
oRng.Collapse Direction:=wdCollapseStart
ActiveDocument.Fields.Add Range:=oRng, Type:=wdFieldSequence,
Text:="MyNum"
End If
End If
Next
ActiveWindow.View.ShowFieldCodes = False
ActiveDocument.Fields.Update

End Sub
 
G

Greg Maxey

Add a line:

If Not Mid(oPar.Range.Text, 3, 3) = "SEQ" Then
oPar.Range.InsertBefore vbTab ' add this line.
Set oRng = oPar.Range.Duplicate
 

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