View Single Post
 
Old 03-20-2019, 06:23 AM
Asuryan33 Asuryan33 is offline Windows 10 Office 2016
Novice
 
Join Date: Oct 2017
Posts: 9
Asuryan33 is on a distinguished road
Default WORD VBA Macro. Find variation of same word.

Hello.

I have a question.

gmayor already helped me on that (thx a lot) but now I used this macro a bit, I have few more questions on it.

The first is about what is between "With Selection.Find" and "End With". As you can see on the code, I have two of them with code between (for sure).
Is it possible to merge them ? if not, what the logic ?.


My second question.... if I track modification on word, I see that the macro highlight the word first, then erase it and replace it with non highlight word.
as consequence, the correction proposed is the non highlited word and the part corrected is the highlited word (It should be the opposit). It's not a big deal but I'm curious of the "Why"

my third question is about a possible option.
Some of my text are in french. And in French, conjugaison can be complicated.
The infinitive verb for walk is "Marcher", but the verb can be wrote "Marche", "Marché", "Marchez", "Marchons" ...etc.

On my list, I only have the infinitive. Is it possible to ask the macro to find a higligt all
"Marcher la nuit", "Marchez la nuit" and "Marchons la nuit" without writing all variant in my list of word ?



Code:
Sub Hightlightfromlist()
Dim sCheckDoc As String
Dim docRef As Document
Dim docCurrent As Document
Dim i As Integer
Dim oPara As Range


sCheckDoc = "C:\Users\ttv574\Desktop\checkphrases.docx"
   Set docCurrent = Selection.Document
    Set docRef = Documents.Open(sCheckDoc)
    docCurrent.Activate
    Options.DefaultHighlightColorIndex = wdYellow

    With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .MatchWholeWord = True
        .Replacement.Highlight = True
        .Replacement.Text = "^&"
        .Forward = True
        .Format = True
        .MatchCase = False
        .MatchWildcards = False
    End With

    For i = 1 To docRef.Paragraphs.Count
        Set oPara = docRef.Paragraphs(i).Range
        oPara.End = oPara.End - 1
        With Selection.Find
            .MatchWholeWord = True
            .Wrap = wdFindContinue
            .Text = oPara.Text
            .Execute Replace:=wdReplaceAll
        End With
    Next i

    docRef.Close
    docCurrent.Activate
    Set docRef = Nothing
    Set docCurrent = Nothing
    Set oPara = Nothing
   
End Sub
Reply With Quote