Word VBA to insert pictures (from file) "In Front Of Text"

  • Hi All


    I have a couple of renders of signitures which I would like to put insert "In Front Of Text" on various word documents.


    Is there a VBA code that I could put into the Normal.doc as a Macro that just inserts a picture (via the file path/name) onto of a documents?


    Thanks

  • Re: Word VBA to insert pictures (from file) "In Front Of Text"


    You don't really give enough info, but the following will display a dialogue to select a picture and insert to a bookmark. This can easily be changed to determine a name from the logged in user and insert at the current insertion point (That's where your post is not clear).



    The macro can be linked to a button or hot-key.

  • Re: Word VBA to insert pictures (from file) "In Front Of Text"


    Sorry for not being clear.


    Basically I have three rendered signitures for three users, the users will open up a document, and then they need to put their signiture on it and save it. This is to save them printing it out just to sign and then scanning back in.


    Since its such a simple step I wasn't going to bother to code the whole thing. Was just after a macro to insert a picture anywhere on the document as it doesn't matter cause the user will move it around to where they want it anyway. But its needs to be in front of text (so that by moving it, it doesn't mess up the document).


    There are only three picture files so I was going to just hard code the picture paths in, and then assign a shortcut key so user A would simply go Ctrl+Shift+A for his, and User B would go Ctrl+Shift+B for his etc?

  • Re: Word VBA to insert pictures (from file) "In Front Of Text"


    You could name the sigs same as the user name, and then using, along with other code, the

    Code
    ENVIRON("USERNAME")

    command insert the appropriate sig at the current insertion point. Only one procedure that way.


    Sorry about the OTT sample, getting the pic using the dialogue was just an example. The bookmark can be ignored as well if you're happy to insert where the cursor is.

  • Re: Word VBA to insert pictures (from file) "In Front Of Text"


    I happy to insert anywhere, as the user will have to move it around to find a blank ish part of the page anyway. Even though they are renders its still better to put them over a blank ish part. I could certainly save them under the user name and use that code that would be great.


    The code I need though is just the insert from file code? I have no idea how to write this?

  • Re: Word VBA to insert pictures (from file) "In Front Of Text"


    Slightly modified... To insert a picture named as <USERNAME>.jpg at the current insertion point:


    The ENVIRON() command returns the logged in user name...

  • Re: Word VBA to insert pictures (from file) &quot;In Front Of Text&quot;


    Awesome thanks, is there a code to make in "In Front of Text" so it can be moved around freely without messing up the document?

  • Re: Word VBA to insert pictures (from file) &quot;In Front Of Text&quot;


    Add 2 lines after the 'With vShape' statement


    Code
    With vShape
            .Select
            Selection.ShapeRange.WrapFormat.Type = wdWrapFront
            .LockAspectRatio = True
            .Height = InchesToPoints(1)
        End With


    *EDIT*


    On second thoughts, it really should have error handling - the file just may not exist or is corrupt (Not an unknown thing to happen!)...


    Complete revised code:

  • Re: Word VBA to insert pictures (from file) &quot;In Front Of Text&quot;


    Thanks cytop, I think its getting close


    But the code fails at:


    Selection.ShapeRange.WrapFormat.Type = wdWrapFront


    With a run time 4198 command failed error?

  • Re: Word VBA to insert pictures (from file) &quot;In Front Of Text&quot;


    Sorry - I can't replicate that.


    Error 4198 seems to be some sort of timing or synchronisation error. Can only suggest the following to pause processing and allow Word to 'catch up'


    Code
    With vShape
            .Select
            DoEvents: DoEvents
            Selection.ShapeRange.WrapFormat.Type = 3  'wdWrapFront
            .LockAspectRatio = True
            .Height = InchesToPoints(1)
        End With


    Sorry I can't be more precise. I'll have a closer look when I have time later.

  • Re: Word VBA to insert pictures (from file) &quot;In Front Of Text&quot;


    When you set the picture as in front of text manually it opens up the "Horizontal Alignment" options perhaps that needs to be set also?


    I tried the above but it still gets the 4198 error on the same line.


    I found this article on the error:


    http://support.microsoft.com/d…spx?scid=kb;en-us;Q228701


    Which sort of makes sense, as the picture is being selected... But I cant see any hyperlink objects in the code and there are no hyperlinks (as I know them) on the document?


    Sorry, I have it working now... I opened one of the docs and noticed it was running in Compatibility Mode, so I went to File then converted to current format, saved and reopened... And now the code above works perfectly. Dont know if this can help you figure out why it would make a difference.



    Cheers though big help.

  • Re: Word VBA to insert pictures (from file) &quot;In Front Of Text&quot;


    Quote from cytop;680650

    Sorry - I can't replicate that.


    Many Thanks, let me suggest to include .ConvertToShape in order to float the image "In Front Of Text"


    I'm using this to insert a image stamp with transparent background


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!