Need help doing a search & replace script

K

Krye

Problem:
I am trying to search a Word Document to extract all instances of
paragraph numbers.

For example:

1.2. Blah Blah

1.10.3.5.3.2. More Blah

Word's search feature allows you to find specific sequences such as

^p^#.^#^#. <-- Where ^p is a paragraph mark and ^# is a number. So this
search would find all paragraph numbers with 1 digit, a period, 2
digits, and a period.

My possible solution: So I want to find all paragraph numbers that are
up to six deep (I.E. 1.2.3.4.5.6.) via a VB Script. I figure the best
way is to make an array of all possible combinations and plug each
combo into the search until I've met all possible combinations. Problem
is, I haven't a clue how to pull it off the array.

There has to be an easy way to do this that i'm just missing:

A 2 number example (I.E. 1.2. or 1.18.) in psudeo code:


Legend:
# 1 digit
## 2 digits

START CODE
Look for #.
Look for ##.
Look for #.#.
Look for #.##.
Look for ##.#.
Look for ##.##.
END CODE



Now obviously you can just put that into a few loops simply enough. But
I can't get it right when I upscale it to 6 numbers.

Perhaps there's a better way of pulling it off?

Any help appreciated. Thanx!
 
H

Helmut Weber

Hi,
there are many ways to do that.
Some are faster, some are more complicated,
some are easier to debug or to adapt to different
situations. You might like to try this:
Dim l As Integer
With Selection
.WholeStory
.Collapse
.Range.InsertBefore vbCrLf
With .Find
.ClearFormatting
.text = "^013[0-9]*. "
.Replacement.text = ""
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
.Execute
While .Found = True
s = Selection.text
l = Len(s)
MsgBox Right(s, l - 1)
.Execute
Wend
End With
.HomeKey unit:=wdStory
.Delete
End With
You have to take care of find.parameters omitted
for brevity.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, W98
 

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