Solved

Find text on word document inside textbox

Posted on 2014-04-17
2
591 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

863 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

25 Experts available now in Live!

Get 1:1 Help Now