全局代码
Public Sub thread_sub1(ByVal file As object)
Dim app As New MSWord.Application
try
Dim doc = app.Documents.Open(file)
Dim gjzs As String = "Test|Abcdefg|test"
Dim flag As Boolean = False
For Each gjz As String In gjzs.split("|")
app.ActiveWindow.Selection.WholeStory
With app.ActiveWindow.Selection.Find
.HitHighlight(gjz, RGB(255, 255, 0), , , , , , , True)
End With
If app.ActiveWindow.Selection.Find.Execute Then flag = True
Next
If flag = False Then
Doc.close
app.quit
Else
app.Visible = True
End If
catch ex As exception
msgbox(ex.message)
app.Quit
finally
End try
End Sub
调用代码
Dim dlg As New FolderBrowserDialog
If dlg.ShowDialog = DialogResult.Ok Then
MessageBox.Show("需要检索的文档目录是:" & dlg.SelectedPath,"提示")
End If
Dim s As String = ""
For Each file As String In FileSys.GetFiles(dlg.SelectedPath)
If file.ToLower.EndsWith(".doc") Then
Dim t0 As Threading.Thread
t0 = New Threading.Thread(AddressOf thread_sub1)
t0.Start(file)
End If
Next