前提
ExcelVBAで文書内で検索ワードを自動検索するマクロを作っています。
VBAの検索様式、find関数に関して、分からないことがあるため教えていただきたいです。
実現したいこと
・平仮名カタカナを識別した検索結果を得る。
現状、「ネジ」で検索すると「ねじ」も識別されており、
正確な「ネジ」の出現件数が分からない。(逆も同様)
「ネジ」の検索結果に「ねじ」が含まれないようにしたい。
該当のソースコード
VBA
1' Excel ファイル内の文字検索 2Private Sub grepExcel(ByVal searchWord, ByRef myBook As Workbook, ByVal Path As String, ByVal buf As String) 3 4 5 Dim filePath 6 Dim wb As Workbook 7 Dim readSheet As Worksheet 8 Dim Rng As Range 9 Dim findResult 10 11 fullPath = Path & "\" & buf 12 13 Application.DisplayAlerts = False 14 Application.ScreenUpdating = False 15 16 Set wb = Workbooks.Open(Filename:=fullPath, UpdateLinks:=0, ReadOnly:=True, IgnoreReadOnlyRecommended:=True, Password:="") 17 18 If Err.Number = 1004 Then 19 20 Err.Clear 21 22 Else 23 24 For Each mysheet In wb.Worksheets 25 26 Set findResult = mysheet.Cells.Find(searchWord, LookAt:=xlPart) 27 Dim findCell As Range 28 Set findCell = findResult 29 30 If Not (findCell Is Nothing) And Not (findResult Is Nothing) Then 31 32 Do 33 If Not (findCell Is Nothing) And Not (findResult Is Nothing) Then 34 Call writeSheet(myBook, Path, buf, mysheet, findCell) 35 Set findCell = mysheet.Cells.FindNext(findCell) 36 If findCell Is Nothing Then 37 Exit For 38 End If 39 Else 40 Exit For 41 End If 42 Loop While findCell.Row <> findResult.Row 43 44 End If 45 46 Next 47 48 End If 49 50 wb.Close savechanges:=False 51 52 Application.ScreenUpdating = True 53 Application.DisplayAlerts = True 54 55End Sub
回答2件
あなたの回答
tips
プレビュー