Searching and underlining all occurences of a word

D

Dave Neve

Hi

I know that when I am in my table, I can initiate a search for a word and I
can ask 'Word' to underline all occurences of the word (options in search).

So, I have tried to record a macro to do the same to save me from having to
select the column and tick the right boxes every time (complete word,
underline all occurences)

But their are two things that have me stumped

Instead of having a particular word to search for in my macro (eg. 'mai') ,
I'd like the macro to fill itself in with the selected word.

The second thing is that the macro which was recorded by Word doesn't seem
to behave in the same way. It simply doesn't underline all occurences of the
word.

The macro is as follows and thanks for any help in advance

Dave Neve

Sub SearchThai()
'
' SearchThai Macro
' Macro enregistrée le 07/10/2004 par Dave Neve
'
Selection.SelectColumn
Selection.Find.ClearFormatting
With Selection.Find
.Text = "mai"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End Sub
 
H

Helmut Weber

Hi Dave,
I think we have discussed problems rising from
the fact, that there is no column.range before.
Remeber?
OK, here comes another one:
Sub Dave()
Dim oCll As Cell
Dim sSrc As String
sSrc = Selection.Text
Resetsearch
Selection.SelectColumn
For Each oCll In Selection.Cells
With oCll.Range.Find
.Text = sSrc
.Replacement.Text = sSrc
.Replacement.Font.Underline = wdUnderlineSingle
.MatchWholeWord = True
.Execute Replace:=wdReplaceAll
End With
Next
Resetsearch
End Sub
' ---
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
 
D

Dave Neve

Hi

Don't even remember what I discussed last night let alone 6 months ago.

But your remark has triggered my ever curious nature.

If there is no 'column range' how comes that you can collect a column in
Word with the mouse or in the menu (tables, selection, column)

If Word can recognize a column, surely it must be writable in VBA somehow???

Thanks in advance
 
H

Helmut Weber

Hi Dave,
try this and see the difference.
All occurences of "mai" will be underlined,
whereever they are in the table.
---
Dim oCll As Cell
Dim sSrc As String
sSrc = Selection.Text
Resetsearch
Selection.SelectColumn
'For Each oCll In Selection.Cells
With Selection.Find
.Text = sSrc
.Replacement.Text = sSrc
.Replacement.Font.Underline = wdUnderlineSingle
.MatchWholeWord = True
.Execute Replace:=wdReplaceAll
End With
'Next
Resetsearch
 

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