Some simple VB code needed please

  reddwarfcrew 09:33 14 Apr 2005
Locked

I need some vb code that performs a 'find' in word and if it does find what I'm looking for then some code runs. ie:


If the document contains the word 'yourself' Then etc etc

I know how to do the if statement, just not the first part.

Thanks.

  Rigga 10:04 14 Apr 2005

Try the below for an example of running a find from within Word VBA.

Document.Find.ClearFormatting
With Document.Find
.Text = "AWord" 'The Text to Find here!
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
If Document.Find.Execute = True Then

'place code if found here!!!!

End If


HTH
R.

  Rigga 10:07 14 Apr 2005

AAAAAAArrrrrrggghhhhhh formattng.. I'll try again..

Document.Find.ClearFormatting

With Document.Find

.Text = "AWord" 'The Text to Find here!

.Replacement.Text = ""

.Forward = True

.Wrap = wdFindContinue

.Format = False

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

If Document.Find.Execute = True Then

'place code if found here!!!!

End If


HTH.
R.

  reddwarfcrew 10:09 14 Apr 2005

looks good, I'll give it a go in a few mins

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

How secure is your Wi-Fi?

AMD vs Intel: we put the most powerful desktops for designers and artists head-to-head

iPhone tips & tricks

Les meilleurs ordinateurs portables 2017