Find, select and display text in Word

  • Thread starter Thread starter RobProsfora
  • Start date Start date
R

RobProsfora

Guest
Hi,


I'm trying to find and selecting a paragraph text in a word document. My code, so far, finds the text from a textbox as it shows a message to confirm. But I also want to display the header text found in the active Word document. Could you please help me with a solution for that?

Here is my code so far.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim word As New Microsoft.Office.Interop.Word.Application
Dim doc As New Microsoft.Office.Interop.Word.Document
Dim findText As String = TextBox1.Text

'doc = word.Documents.Open(My.Settings("Logo").ToString() + "Clausules.docx")
doc = word.Documents.Open("c:\Temp\Clausules.docx")
word.Visible = True
doc.Activate()

doc.Content.Find.ClearFormatting()
Try
If doc.Content.Find.Execute(findText) = True Then
MessageBox.Show("tekst gevonden")
With doc.Content.Find
Selection.MoveEnd(wdLine, Count:=1)
End With
Else
MessageBox.Show("tekst niet gevonden")
End If
'doc.Close()
'word.Quit()
Catch ex As Exception
doc.Close()
word.Quit()
End Try


End Sub

Continue reading...
 
Back
Top