Return Picture/image From Word Document To Imagebox On Userform

  • Hi Guys


    Currently there is a way to "Return text from Word Doc", whereby I use the bookmarks range and text attributes to add the word contents to a textbox on a userform. Is it possible to return an embedded picture from Word to a Image box on a userform.


    In summary, I am using the Word Doc as a store/database for text and pics. then reference this info by means of a bookmark and insert the info into a userform textbox or imagebox.


    Help is appreciated.


    Regards
    Ramiz

  • Re: Return Picture/image From Word Document To Imagebox On Userform


    Hi Andy


    Thank you for the reply. I will look at the example and provide feedback on my success.


    Thanks

  • Re: Return Picture/image From Word Document To Imagebox On Userform


    Quote from Andy Pope

    Have a look at the PastePicture example on Stephen's site.
    http://www.oaltd.co.uk/Excel/Default.htm


    You will still need to locate the picture within the word doc but the code will allow you to display the copied image in a userform


    :( Andy


    Thanks for your help so far, I have manage to locate the picture in the word document by means of a bookmark. I then select and copy the bookmark and it is then placed to the clipboard. Unfirtunately, the function the takes it from the clipboard and inserts it to the image control on the form, references excel specific properties and code.


    I do not know what the Word equivalents are. thus when I run the code then the errors are about the xl references.


    Thanks
    Ramiz

  • Re: Return Picture/image From Word Document To Imagebox On Userform


    Quote from Andy Pope

    Can you post your code and an example doc file.


    Andy


    Once again thank you.


    A colleague and I have designed a training manual with MS Word; though I want the content and the document pages to be in the background. The user will then access the information via "links" on the userform that I have created by means of the click event of the label.


    This sub routine then references the applicable bookmark and places the text in the userform textbox. Certain topics have examples of pics that I also want to display on the userform by means of an image object. Once again, I have bookmarked the picture and when the picture "link" is clicked, the picture will be copied to the clipboard. Then using the the code you directed me to earlier, it will then take the pic from the clipboard and insert in the image. But I unfortunately can't convert the code to Word.


    Thanks


    The file is too big for uploading. Please find code below



    In each selection there is a picture that is also referenced by a bookmark (I have not included the code though; but how to take it from the clipboard is the problem.

  • Re: Return Picture/image From Word Document To Imagebox On Userform


    I created a word doc with 2 bookmarks.
    One on a range of text the other on an image.


    The userform had a button, image and textbox.
    [vba]Private Sub CommandButton1_Click()


    TextBox1.Text = ActiveDocument.Bookmarks("Contract").Range.Text
    ActiveDocument.Bookmarks("Whale").Select
    Selection.CopyAsPicture

    Set Image1.Picture = PastePicture(2)

    End Sub[/vba]


    The only change I needed to make to the modPastePicture code module was to add to public const.


    [vba]Public Const xlPicture = 1
    Public Const xlBitmap = 2[/vba]

  • Re: Return Picture/image From Word Document To Imagebox On Userform



    Andy


    Thank you very much for your time and professional assistance. The code you posted was perfect and it works like a charm. All I need to do know is to play around with the dimensions of the image to be able to get the correct view of the image. (i.e. resolution and size)


    Regards

  • Re: Return Picture/image From Word Document To Imagebox On Userform


    You can set the properties of the image control such that the picture resizes to fit the control.


    Or you could place the image within a frame and enable the scrollbars so the image can be show at 100% size and moved around if too large for the frame.

  • Re: Return Picture/image From Word Document To Imagebox On Userform


    Quote from Andy Pope

    You can set the properties of the image control such that the picture resizes to fit the control.


    Or you could place the image within a frame and enable the scrollbars so the image can be show at 100% size and moved around if too large for the frame.


    Andy


    I was playing around with the properties of the image control and managed to get the picture to resize accordingly but was unaware of the thframe with the scrollbars and will give it a try.


    Once again, great help that you have provided::D


    Regards

  • Re: Return Picture/image From Word Document To Imagebox On Userform


    Hi


    The code and the image frame works brilliantly. Though, I have encountered a bit of a problem. As mentioned in the earlier posts I am using the word document as a repository and then referencing the document to display text and pictures on a form. This form acts as an electronic job aid. The problem I have encountered is that because I use macros the functionality is dependent on the users macro security level.


    How can I rectify this?


    Regards

  • Re: Return Picture/image From Word Document To Imagebox On Userform


    You need to set the workbook up so that the functionality is hidden unless macros are enabled. Then you would add functionality and remove it when closing the workbook.


    If no macros then the workbook just lets the user know how to activate macros.


    There are posts on this approach on the forum.

Participate now!

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