Solved

Find text on word document inside textbox

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

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 15

Expert Comment

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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
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…

829 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