VB.net 2005 express - Office Word 2003
Office 11 library =references
I need to make from VB.net search in Word for these words: "tree", "bus",
"car"...(complete list contains ca. 50 words)
when find founds word "tree", BOLD entire Row (where is that word "tree"),
search next instance of "tree", BOLD entire Row... when find founds word
"bus", BOLD entire Row, search next instance of "bus", BOLD entire Row...
This code works for only one word:
Imports Word = Microsoft.Office.Interop.Word
Private Sub btnBold_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnBold.Click
Dim oWord As New Word.Application
Dim oDoc As Word.Document
Dim path As String = Me.TextBox1.Text
oWord.Visible = True
oDoc = oWord.Documents.Open(path)
Dim intFound As Integer = 0
Dim rng As Word.Range = oDoc.Content
rng.Find.ClearFormatting()
rng.Find.MatchCase = True
rng.Find.MatchWholeWord = True
rng.Find.MatchWildcards = False
rng.Find.MatchSoundsLike = False
rng.Find.MatchAllWordForms = False
rng.Find.Text = "bus"
rng.Find.Execute()
Do While rng.Find.Found = True
rng.Select()
rng.Bookmarks("\Line").Range.Font.Bold = True
intFound += 1
rng.Find.Execute()
Loop
oDoc.SaveAs(path)
oDoc.Close()
oDoc = Nothing
oWord.Quit()
oWord = Nothing
End Sub
-------------------------
-------------------------
This code DONT WORK, but i'm trying :). I tryed couple of variants and no
success.
Any help apriciated
Dim oWord As New Word.Application
Dim oDoc As Word.Document
Dim path As String = Me.TextBox1.Text
oWord.Visible = True
oDoc = oWord.Documents.Open(path)
Dim rDcm As Word.Range = oDoc.Range
With rDcm.Find
..MatchCase = True
..MatchWholeWord = True
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
..Execute(FindText:="tree")
..Execute(FindText:="bus")
..Execute(FindText:="car")
'etc... (other words)
While .Execute
rDcm.Select()
rDcm.Bookmarks("\Line").Range.Font.Bold = True
End While
End With
oDoc.SaveAs(path)
oDoc.Close()
oDoc = Nothing
oWord.Quit()
oWord = Nothing
End Sub