79822109

Date: 2025-11-17 09:44:25
Score: 1
Natty:
Report link

My PC is set to a Japanese environment, so please take that into consideration.

Microsoft® Word for Microsoft 365 MSO (バージョン 2510 ビルド 16.0.19328.20190) 64 ビット

Since I am using MatchWildcards, the Excel sheet is assumed to contain data as shown below.

Excel Example

A B
------------------ ------------
[Hh]yla [Cc]inerea Hyla cinerea
[Bb]ig [Aa]pple Big apple
ABcd Abcd

In the code in question, the following error occurred:
-----------------------------------

実行時エラー'6182’:

MatchPhrase, MatchWildcards, MatchSoundsLike, MatchAllWordForms,

MatchFuzzy パラメーターは、同時に True に設定することはできません。

-----------------------------------

(1) I am changing the properties of Find for this purpose.(MatchFuzzy = False)
(2)I modified the processing after With Selection.Find.

Changing rng.Text inside a Do While loop results in an infinite loop, so I stored the searched ranges in an array and changed each Range's properties after the search was completed.  

before image

enter image description here

after image

enter image description here

code

Dim myarray_range(1000) As Range  
Dim cnt_ranges As Long  
cnt_ranges = 0  
With Selection.Find  
    .Forward = True  
    .MatchFuzzy = False  
    .MatchWildcards = True  
    .Wrap = wdFindStop  
    .MatchCase = False  
    Do While .Execute(FindText:=myarray(i, 1)) = True  
        Set myarray_range(cnt_ranges) = Selection.Range  
        cnt_ranges = cnt_ranges + 1  
        Debug.Print Selection.Range.Text  
    Loop  
End With  
Dim j As Long  
For j = 0 To cnt_ranges - 1  
    With myarray_range(j)  
        .Font.Italic = True  
        .Font.Bold = True  
        .Font.Color = RGB(200, 187, 0)  
        .Font.Name = "Times New Roman"  
        '.Text = UCase(Left(.Text, 1)) & LCase(Mid(.Text, 2))  
        .Text = myarray(i, 2)  
    End With  
Next j
Reasons:
  • Blacklisted phrase (1): enter image description here
  • Long answer (-1):
  • Has code block (-0.5):
  • Filler text (0.5): ------------------
  • Filler text (0): ------------
  • Filler text (0): -----------------------------------
  • Filler text (0): -----------------------------------
  • Low reputation (1):
Posted by: motosann