finding word and inserting text above

S

shark102

hello

I need to find a word 'account' in a text and type sth (eg. ********* - this
is supposed to be just a line separating sets of data imported from database)
2 lines above word 'account'.

I recorded macro which finds word 'account' and started working on it but
got lost so there is no point copying it here.

Any help appreciated.
 
H

Helmut Weber

Hi,

if the lines,
which are in fact one line paragraphs,
above "account" are at least as long
as the line containing "account" until "account", then:

Sub Macro10()
ResetSearch
Selection.HomeKey unit:=wdStory
Selection.ExtendMode = False
With Selection.Find
.Text = "account"
.MatchCase = True
While .Execute
Selection.Collapse
Selection.MoveUp unit:=wdLine, Count:=2
Selection.TypeText "*******"
.Execute
Wend
End With
ResetSearch
End Sub

' -------

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

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

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