D
Dave Neve
Hi Helmut,
Sorry to yet again have to ask but I just can't master VB.
You gave me two macros last week which I have copied below.
There are several problems which I just can't seem to get round.
1 The macros find words in all colums even though there is an instruction
Selection.SelectColumn
Something in the macro is overriding this instruction!
2 The instruction
.Replacement.Font.Underline = wdUnderlineSingle
is no good for me as I use 'underline' to indicate sth already (words
with low tones). Also, it is 'permanent' in that it doesn't disappear at the
end of a search. (if I make it disappear, all my underlined words are
changed which is a disaster)
I need the same behaviour as when Word searches. I have tried to see what
Word does by recording a macro and I think it is
.Selection. Extend
but I just can't get my macros to search for a Word , select and extend
every occurence
In summary, I would like to write a code to do the following which I can
already do with Word but it takes time
1 I select a word by clicking on it.
2 Macro searches for this word in a column (I tick various options before
running the search)
3 Macro 'highlights' every occurence of this word in column ('highlight
here' = extends and not 'highlight')
4 When I click on the page elsewhere, all the selected words return to
normal (no traces of search are left on the words found)
Thanks
PS I am wading through my second book on VBA: Création de Macros VBA by
Campus Press.
Thanks
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
---
Sorry to yet again have to ask but I just can't master VB.
You gave me two macros last week which I have copied below.
There are several problems which I just can't seem to get round.
1 The macros find words in all colums even though there is an instruction
Selection.SelectColumn
Something in the macro is overriding this instruction!
2 The instruction
.Replacement.Font.Underline = wdUnderlineSingle
is no good for me as I use 'underline' to indicate sth already (words
with low tones). Also, it is 'permanent' in that it doesn't disappear at the
end of a search. (if I make it disappear, all my underlined words are
changed which is a disaster)
I need the same behaviour as when Word searches. I have tried to see what
Word does by recording a macro and I think it is
.Selection. Extend
but I just can't get my macros to search for a Word , select and extend
every occurence
In summary, I would like to write a code to do the following which I can
already do with Word but it takes time
1 I select a word by clicking on it.
2 Macro searches for this word in a column (I tick various options before
running the search)
3 Macro 'highlights' every occurence of this word in column ('highlight
here' = extends and not 'highlight')
4 When I click on the page elsewhere, all the selected words return to
normal (no traces of search are left on the words found)
Thanks
PS I am wading through my second book on VBA: Création de Macros VBA by
Campus Press.
Thanks
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
---