Microsoft Office Forums

Go Back   Microsoft Office Forums > >

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


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 ?

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)
    Options.DefaultHighlightColorIndex = wdYellow

    With Selection.Find
        .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

    Set docRef = Nothing
    Set docCurrent = Nothing
    Set oPara = Nothing
End Sub
Reply With Quote

microsoft word 2016, vba

Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and Replace Numbers Macro VBA in Microsoft Word Yotem189 Word VBA 3 09-20-2018 05:55 AM
WORD VBA Macro. Find variation of same word. Need Macro for Find and Replace, Inserting logo in Ms-Word. Aswinraj Word VBA 1 06-05-2016 04:33 PM
Find word then call signature macro Dave T Word VBA 4 03-28-2016 11:18 PM
Macro to find and format with whole word match option Marrick13 Excel Programming 0 03-13-2016 10:04 AM
Macro to find a word in first row of table and then perform two macros hmsrose Word VBA 5 01-30-2015 12:17 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:12 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd. is not affiliated with Microsoft