Replace text for image

Posted on 2012-09-19
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

    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 13

    Expert Comment

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

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
    Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
    The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
    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 …

    746 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

    18 Experts available now in Live!

    Get 1:1 Help Now