Word Macro Search Next

R

Raymond RUSSELL

Hello all

My main question is :
What is the syntax for searching for one prespecified term in a Word (2000)
doc,
stopping to edit it, then progressing to the next occurrence, etc to the end
of the doc,
then searching for a different prespecified term, and going through the same
process.
I want to search my docs for a series of errors that frequently occur.
Can some kind soul please write it out for me ?

My second (not so important) question is :
I'm pretty literate in Word but completely at sea with the Macro language.
As Word has progressed from version to version I've always asked wherever
possible to have my macros transferred and under Tools-Macros they appear
all to be
listed. Some, however, have the word MAIN written after them - and these do
not
respond when I assign them a keyboard shortcut. Can anyone explain ?

Best regards from Ray
 
H

Helmut Weber

Hi Raymond,

I can only respond to your first question.
I don't think you want a program, which
executes a search, returns control to the user,
lets him edit some text, and continues afterwards.
Might be possible, but it's nothing for someone
who is "completely at sea with the Macro language".

Just search for your text,
click into the doc, do your editing,
and hit "find next".

Your macros were automatically converted from Wordbasic
to VBA, Visual Basic for Applications.

The last time I saw such code is 9 years ago.
So someone with better memory might like to take over.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
R

Raymond RUSSELL

Hello Helmut

(sent this to you direct - instead of the group - sorry)

I think I was a bit woolly explaining what I want.

I want to search, for example,
for <space> followed by <.>,
for decimal commas (I translate from German
and sometimes forget to change these to decimal points),
for <a> followed by <a> or <e> or <i> or <o> or <u>,
for <an> followed by a consonant.

I can do all these things on foot
but, as you can imagine, this is very tedious.
That's why I'd like to do it in a macro
(to which I could add such similar elements).

The macro could return to the start of the doc
each time until I've edited out all the mistakes the macro finds
and I can do a clear run at the end.

Any further suggestions ?

Best regards from Ray
 
H

Helmut Weber

Hi Raymond,

there is no simple and short answer, IMHO.

As I am doing text conversion from english to german
and vice versa as well, I'd say,
what you need is a collection of bullet-proof rules, like replace
" ." with ". "
" ," with ", "
Replace the last "." in a sequence of numerals by ","
and all others "," by "."

Could be a nice little project.

Again, IMHO, too complicated,
to be handled with tips and tricks in a newsgroup.
I'm sorry.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
R

Raymond RUSSELL

Hello all

Let me make things a bit simpler.

What I'm looking for is a WORD macro
which would look for a certain string in a document
stopping on the first occurrence, allowing me to change it,
then jumping back to the beginning of the document
and searching for the next occurrence of the same string,
and so on, until I've changed all occurrences.
Then I'd like to repeat this macro for other strings.

Best regards from Ray
 
H

Helmut Weber

Hi Ray,

I've experimented a lot, but can't think of anything
but using two or three different macros.

The idea is as follows:
Set up a simple txt file,
which contains the list of strings to search for.
Create a documentvariable with the value 1, like:

Sub StartMe()
ActiveDocument.Variables("Nummer").Value = 1
Selection.HomeKey unit:=wdStory
Selection.ExtendMode = False
ResetSearch
End Sub

Create a second macro to increment the value
of the variable, like:

Sub Continue()
ActiveDocument.Variables("Nummer").Value = _
ActiveDocument.Variables("Nummer").Value + 1
Selection.HomeKey unit:=wdStory
Selection.ExtendMode = False
ResetSearch
End Sub

In a third macro, you read the string with the number
of the document-variable from the txt-file, like:

Sub Test()
Dim l As Long ' lop variable
Dim v As Long ' value from doc variable
Dim s As String ' search string
v = ActiveDocument.Variables("Nummer").Value
Open "c:\test\list.txt" For Input As #1
For l = 1 To v
Input #1, s
Next
Close #1
With Selection.Find
.Text = s
.Execute
End With
End Sub

Assign a shortcut to "Test".

All in all I think, it isn't that complicated,
and if the list is very long, the doc-variable
would even remember how far you got.

Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub
 

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