[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Replace text for image

Posted on 2012-09-19
Medium Priority
Last Modified: 2016-04-04
   Could anyone please how i can replace à text string for an image in word?
So far i have tried this which provides The image every time regardless of The string.
Sub brief()
   Dim obj As LineShape
   Set obj = ActiveDocument.LineShapes.AddPicture(FileName:= _
    "C:\Users\Peter Hintzen\Documents\registratie documenten\handtekening.jpg", LinkToFile:=False, _
    SaveWithDocument:=True, Left:=-35, Top:=560)
       With obj
        .WrapFormat.Type = 3
        .ZOrder 5
       End With
   End Sub
Question by:Phintz
LVL 22

Accepted Solution

Flyster earned 2000 total points
ID: 38414494
This code will open an input box for you to enter your replacement string. It will then replace that string with the image defined by iPath.

  Sub TextToImage()
Dim sReplace As String, iPath As String

    iPath = "C:\Users\Peter Hintzen\Documents\registratie documenten\handtekening.jpg"
    sReplace = InputBox("Enter string to be replaced with image.", "String to Image Replacement", , vbOK)
    With Selection
        .HomeKey Unit:=wdStory

        With .Find
             .Text = sReplace

             Do While .Execute
                 Selection.InlineShapes.AddPicture FileName:=iPath, LinkToFile:=False, SaveWithDocument:=True

         End With
     End With

     With Selection.Find
         .Text = sReplace
         .Replacement.Text = ""
         .Forward = True
         .Wrap = wdFindContinue
         .Format = False
         .MatchCase = False
         .MatchWholeWord = True

     End With
     Selection.Find.Execute Replace:=wdReplaceAll

End Sub 

Open in new window

LVL 14

Expert Comment

ID: 41534327
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

872 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