Solved

Find text on word document inside textbox

Posted on 2014-04-17
2
589 Views
Last Modified: 2014-04-17
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.

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

Open in new window

0
Comment
Question by:koossa
  • 2
2 Comments
 
LVL 14

Accepted Solution

by:
DrTribos earned 500 total points
ID: 40006238
Text box is a shape, I think you have to look inside each shape...

Sub shTest()

Dim sh As Shape

For Each sh In ActiveDocument.Shapes
Debug.Print sh.TextFrame.TextRange.Text
Next sh

End Sub

Open in new window

0
 
LVL 14

Expert Comment

by:DrTribos
ID: 40006681
Glad it helped :-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
Outlook Free & Paid Tools
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now