1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with VBScript Needed - Find/Replace Image in Word Document

Discussion in 'Scripting & Programming' started by Colloghi, Jan 31, 2013.

  1. Colloghi

    Colloghi Kilobyte Poster

    303
    7
    54
    Good Evening All

    Wonder if anyone can help me with hopefully a simple issue. Im not a VBS guru at all, but it is something Ive been playing about with recently and Im pretty much ok with creating frankenstein scripts to suit my needs for other scripts out on the net.

    Ive found a script on the link below, for replacing text in word docs and have used chopped this up to suit my own needs...

    vbscript - VB Script to Find and Replace text in Word Document - Stack Overflow

    Basically my script works on the same principal; It calls a word template we used for our ID badges, asks for users windows Username, then pulls the info from AD and replaces the text "Na. me" and "Job Title", with their relevant details stored from AD.

    It does exactly what I want, apart from one detail....I cant figure how to replace the image with the image of the user.

    Ive done it before where Ive used in another script, something like

    Set objShape = objSelection.InlineShapes.AddPicture(strlogo)


    With the strlogo being defined as the image I want

    But I just wondered whether it would be possible to just detect the image and replace, as it fit in with how the template is:|

    any help would be great!
     
    Certifications: A+, MCP 270, 271, MCDST
    WIP: 290
  2. Gav

    Gav Kilobyte Poster

    447
    14
    27
    First off, I am not a VB expert, I much prefer C# / PowerShell. However, some Googling suggests you can use "^g" to find graphics. Try playing around with '.Text = "serialtext"', but with "^g" instead of serialtext...
     
  3. Colloghi

    Colloghi Kilobyte Poster

    303
    7
    54
    Hi Gav


    Thanks for that, I did come across that, but unfortunately whilst I could replace the graphic by using ^g, it just would not allow you to replace with another graphic:|

    Ive got round the issue now, and rewritten some of the code to match variables from a scri[pt i used for signatures so where in the script he had

    Set WordApp = CreateObject("Word.Application")

    Set objWord = CreateObject("Word.Application"), which meant I could then add in the pic via
    Set objShape = objSelection.InlineShapes.AddPicture(strlogo)


    Its working now, Ill try and post the full code later when I get home just for other people. I know I went wrong with my lack of experience / knowledge with VBscript and programming in general....but meh its working now:D


    cheers again

    :)
     
    Certifications: A+, MCP 270, 271, MCDST
    WIP: 290

Share This Page

Loading...