Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add Picture to Microsoft Word 1

Status
Not open for further replies.

bas

Programmer
Jan 13, 1999
41
US
I'm writing a little VB6 application to do the following:

1. User chooses a jpeg image
2. Labels it with text
3. Clicks OK - a word document opens with the text & image.

I've used ActiveDocument and bookmarks to handle the text. That works fine. And the user can navigate to an image and I display it on my form in an image object.

Now, how do I programatically insert the jpeg to the Word document?

Thanks.
 
Do you actually want to embed the jpeg itself, or just a link to it?
 
For this application either would be fine, but I'll say embedded.

Unless... linking is alot easier?

 
Heh! No, just makes the necessary call a little different:

Selection.InlineShapes.AddPicture "C:\Program Files\Microsoft Image Composer\Buttons\Textures\Aqua aura.jpg", False, True
 
Wow, that works just fine! Thanks for your immediate response.

:->

Do you also know how to control the placement and size of the jpeg into Word? I was thinking to add this jpeg as the "Picture" of my Image control in Word? I'm sorry if this is a completely different question!
 
Sadly I've just spent an evening in the pub, so I'm not really in any condition to answer right now...
 
try something like

Code:
Option Explicit

Sub test()
  Static x As Long
  Dim sFiles(1) As String
  Dim obj As Image
  Dim shp As Shape
  
  sFiles(0) = "C:\WINDOWS\Skell.bmp"
  sFiles(1) = "C:\WINDOWS\Setup.bmp"
  
  x = x + 1
  x = x Mod 2
  
  For Each shp In ThisDocument.Shapes
    If shp.Type = msoOLEControlObject Then
      If TypeOf shp.OLEFormat.Object Is Image Then
        Set obj = shp.OLEFormat.Object
        obj.Picture = LoadPicture(sFiles(x))
        Set obj = Nothing
      End If
    End If
  Next shp
End Sub
 
When I try this, I get this error at shp.Type:

Compile error - Method or data member not found.

I do not use VB very often, seems like Type is not a property of Shape object.

Any ideas?

bas
 
Thanks for your help - this works great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top