I have used the code sample as you mentioned above in the same thread with some modification according to requirement. here I was matching for some keyword in the document If I match these words than, insert hyperink after word(or may be after the sentence.). You can use the same attached document (Sample Test Document.doc) for the testing.
Public Sub AddHyperLinkToSuggestedText(ByVal doc As Document)
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
'Dim section As Section = New Section(oDoc)
'Create format of hyperlink field
'If hyperlink target is URL then you shoul use "HYPERLINK ""{0}"" \o ""{1}"""
Dim hyperlinkFormat As String = "HYPERLINK \l ""{0}"" \o ""{1}"""
Dim myBookmarkName As String = "BookMark1"
Dim myScreenTip As String = "You can move to bookmark using this hyperlink"
sqlCommand = New SqlCommand("Select Suggestedtext from SuggestedText", sqlConnection)
myScreenTip = sqlCommand.ExecuteScalar
Dim myHyperlinkText As String = "TestHyperLink"
'Create field code
Dim hyperlinkFieldCode As String = String.Format(hyperlinkFormat, myBookmarkName, myScreenTip)
'Change text formation
builder.Font.Color = System.Drawing.Color.Blue
builder.Font.Underline = Underline.Single
Dim paraText As String
Dim arrSplitChars As Char() = {" "c}
sqlCommand = New SqlCommand("Select keywords from MatchKeywords ", sqlConnection)
sqlConnection1.Open()
Dim sqlCommand1 As New SqlCommand()
'Dim curParagraph As Paragraph = builder.CurrentParagraph
Dim paraIndex As Integer = 0
Dim chIndex As Integer = 0
For Each section As Section In oDoc
For Each para As Paragraph In section.GetChildNodes(NodeType.Paragraph, True)
If para.HasChildNodes Then
paraText = para.Range.Text
'to process each word of the paragraph
Dim splitSentences As String() = paraText.Split(arrSplitChars, StringSplitOptions.RemoveEmptyEntries)
For Each text As String In splitSentences
dataReader = sqlCommand.ExecuteReader()
While dataReader.Read()
If text = dataReader.GetValue(0).ToString() Then
sqlCommand1 = New SqlCommand("Update MatchKeywords Set Ismatch =1 where Keywords = '" + text + "'", sqlConnection1)
sqlCommand1.ExecuteNonQuery()
builder.MoveToParagraph(paraIndex, chIndex)
builder.InsertField(hyperlinkFieldCode, myHyperlinkText)
End If
End While
dataReader.Close()
chIndex = chIndex + 1
Next
End If
chIndex = 0
paraIndex = paraIndex + 1
Next
Next
sqlConnection.Close()
End Sub