I am creating a small application that searches an MS Word Document for any information contained in parentheses/brackets and eventually prints it to an excel spreadsheet (I'll work on that later.
So far I am able to extract the data from the document and display it in a MsgBox; however, when i try to extract the page number I keep getting read-only errors with the file (assuming it is trying to open a second instance of the file).
Can someone point me in the right direction for extracting the page number with the text I have extracted. The code attached is the same that is giving me the error... without the reference to objPageNumber, the code works to give me only the text in the document.
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Dim objword As Word.Application
Dim objDoc As Word.Document
Dim strWord As String
Dim objSelection As Word.Selection
Dim strInputFile As String
Dim objPageNumber As String
strInputFile = txtInputFile.Text
objword = CreateObject("Word.Application")
objDoc = objword.Documents.Open(strInputFile)
objSelection = objword.Selection
objSelection.Find.Forward = True
objSelection.Find.MatchWildcards = True
objSelection.Find.Text = "\(*\)"
Do While True
If objSelection.Find.Found Then
strWord = objSelection.Text
objPageNumber = objSelection.Information(Word.WdInformation.wdActiveEndAdjustedPageNumber)
MessageBox.Show(strWord & " , Page" & objPageNumber)