Solved

Insert Image into Word Document Bookmark

Posted on 2002-06-27
2
337 Views
Last Modified: 2010-05-18
I have a template set up in Microsoft Word.  There is a bookmark called IMAGE, and that is where I want to insert an image if one is selected from my VB program.  In my VB program I am using a common dialog box to allow people to choose an image and then I have a picture box called picture1 that displays the image, so that a person can see if he/she likes the image before creating the word document with the image in it... the only problem is that I am having trouble inserting the image.  I have tried copying it to the clipboard and pasting it in the bookmark, but that didn't seem to work...here is what I have so far:

    ElseIf UCase$(lsBookmarkName) = "IMAGE" Then
        Clipboard.Clear   ' Clear Clipboard.
        Clipboard.SetData LoadPicture(Me.CommonDialog2.FileName)
       loWord.Bookmarks("IMAGE").Select
       ActiveWindow.ActivePane.Selection.Paste

For some reason it puts whatever is in the next bookmark in the place where I have the IMAGE bookmark...
0
Comment
Question by:zippy221
2 Comments
 
LVL 3

Accepted Solution

by:
schworak earned 50 total points
ID: 7115378
Because the image you are trying to insert is a file it would be much easier to have word do the insert instead of copying and pasting. Try this....

Selection.GoTo What:=wdGoToBookmark, Name:="IMAGE"
Selection.InlineShapes.AddPicture FileName:= _
        "\\Cbs_imd\DATA\users\schworgj\temp\Pictures\Iceberg.bmp", _
        LinkToFile:=False, SaveWithDocument:=True
0
 

Author Comment

by:zippy221
ID: 7121821
Works like a charm!  Thanks!
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

773 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