Macro to find all text in word
HI
I need to run a macro which will find appriopriate entries of text in a document,as given below. I've got it working fine with wildcards. The only problems is the "Find All" option. I want to select all instances of this text in the document - this can be done straight from the Edit/find menu - but I cannot find any way to do this in the macro. I need to do this so that I can then copy the data into Exel.
Private Sub CmdOK_Click()
UserForm1.Hide
Selection.Find.ClearFormatting
With Selection.Find
.Text = "??/01/2007 ???????? terryja1"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute
End With
Selection.Copy
Selection.Copy
finalspread.Sheets("Bhad").Select
finalspread.ActiveSheet.Paste
HELP! :D
Re: Macro to find all text in word
Hi
Welcome to the forums :wave:
Is this what you are trying to do?
VB Code:
Selection.Find.ClearFormatting
With Selection.Find
.Text = "example" 'your text here
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
once you get this you can paste the data to a worksheet(if you want the code for that, lemme know)...
Hope this helps...
Re: Macro to find all text in word
Cheers, but I've run that and it's doing the same as the code I've already got. Hmm, having read my first post I don't think I've explained this very well. At the moment, it only finds and highlights the first instance of the text in the document. I want to get it to highlight every instance. Like I say, you can do this from Edit/Find on the toolbar by ticking the "Highlight all items found in" tickbox. I've tried recording this so that I can see how its doing this, but even that doesn't work if you rerun it.
Re: Macro to find all text in word
Hmm, I see what you mean...
and guess what it is not letting me run other macros as well... for example if i want to 'Unbold' all 'bold' characters in the Word Doc, it's not letting me...
let me see if i can figure out what the problem is...
VB Code:
With Selection.Find
.ClearFormatting
.Font.Bold = True
With .Replacement
.ClearFormatting
.Highlight = True
End With
.Execute Forward:=True, FindText:="", ReplaceWith:="", _
Format:=True
End With