koossa
asked on
Find text on word document inside textbox
Hi
I'm trying to find text inside a textbox in a word document.
I've tried everything, but could not get it to highlight the word that I've searched for.
I want to add a logo where the word [LOGO] is in the document.
The replace all works, but I don't want to replace it, I want to find each word and add a logo picture in it's place.
I'm trying to find text inside a textbox in a word document.
I've tried everything, but could not get it to highlight the word that I've searched for.
I want to add a logo where the word [LOGO] is in the document.
The replace all works, but I don't want to replace it, I want to find each word and add a logo picture in it's place.
Private Sub cmd1_Click(sender As Object, e As EventArgs) Handles cmd1.Click
Const wdFindContinue = 1
Const wdMainTextStory = 1
Dim oApp As Object = CreateObject("Word.Application")
Dim oDoc As Object
oApp.visible = True
oDoc = oApp.Documents.open("C:\doc.DOC")
Dim oStory As Object
For Each oStory In oDoc.StoryRanges
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
With oStory.Find
.Text = "[LOGO]"
.Replacement.Text = ""
.Wrap = wdFindContinue
.Execute()
MsgBox(oApp.selection.text)
End With
oStory = oStory.NextStoryRange
End While
End If
Next oStory
oDoc = Nothing
oApp = Nothing
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad it helped :-)