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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert and Edit picture 1

Status
Not open for further replies.

TimTDP

Technical User
Feb 15, 2004
373
ZA
Using VBA, how do I insert, and edit, a picture in Word 2000.
(I will run the code from an Access 2000 form)

 


Hi,

Have you tried using the macro recorder?

Skip,

[glasses] [red]Be Advised![/red]
The band of elderly oriental musicians, known as Ground Cover, is, in reality...
Asian Jasmine![tongue]
 
Yes I have but for some reason the macro recorder will not allow me to edit the picture!
 


What do you mean by EDIT? Does that mean opening a Graphic EDIT application (not in Word)?

Skip,

[glasses] [red]Be Advised![/red]
The band of elderly oriental musicians, known as Ground Cover, is, in reality...
Asian Jasmine![tongue]
 
I need to:
change the height and width of the graphic
align it centrally.
set the layout to "Behind text"
 


That is not editing the picture. That's modifying the size and position properties.

So you already have code that Adds the object. It gets added as an InLineShape. Need to be changed to a Shape.

Here's how to FOOL Word in the Macro Record mode.

1) record adding the pic - turn off the recorder.

2) Select the pic, Format/Picture -- change the Layout to IN FORNT OF TEXT. OK to get out of format.

3) Turn on the recorder, Format/Picture -- change layout to BEHIND TEXT -- change the size and location. - turn off the recorder

Now observe your code and modify to suite.

Skip,

[glasses] [red]Be Advised![/red]
The band of elderly oriental musicians, known as Ground Cover, is, in reality...
Asian Jasmine![tongue]
 
Thanks Skip

This is what I got:
Selection.ShapeRange.Fill.Visible = msoFalse
Selection.ShapeRange.Fill.Transparency = 0#
Selection.ShapeRange.Line.Weight = 0.75
Selection.ShapeRange.Line.DashStyle = msoLineSolid


My code is like this:
With objWord.ActiveDocument.Bookmarks
.Item("PreparedFor").Range.Text = rst!PreparedFor
.Item("PreparedForAddress").Range.Text = rst!PreparedForAddress
.Item("GraphicFile").Range.InlineShapes.AddPicture "C:\Documents and Settings\Tim\My Documents\210.jpg", False, True

.Item("GraphicFile").Range.ShapeRange.Fill.Visible = msoFalse

The above line fails with run time error 424 - object required.

Can you help with the syntax?
 


Code:
    Dim oShp As Shape
'stuff    
    With objWord.ActiveDocument.Bookmarks
    .Item("PreparedFor").Range.Text = rst!PreparedFor
    .Item("PreparedForAddress").Range.Text = rst!PreparedForAddress
    Set oShp = .Item("GraphicFile").Range.InlineShapes.AddPicture("C:\Documents and Settings\Tim\My Documents\210.jpg", False, True)
    End With
        
    With oShp
        .Fill.Visible = msoFalse
        .Top = iTopPoints
    End With
'stuff
    Set oShp = Nothing

Skip,

[glasses] [red]Be Advised![/red]
The band of elderly oriental musicians, known as Ground Cover, is, in reality...
Asian Jasmine![tongue]
 
Set oShp = .Item("GraphicFile").Range.InlineShapes.AddPicture("C:\Documents and Settings\Tim\My Documents\210.jpg", False, True)

returns a run time error 13 - type mismatch
 


Change the Dim statement to define an InLineShape

Skip,

[glasses] [red]Be Advised![/red]
The band of elderly oriental musicians, known as Ground Cover, is, in reality...
Asian Jasmine![tongue]
 
A last question if I may:

how do I use the ZOrder msoSendBehindText

I have tried .ZOrder msoSendBehindText but get "Method or Data member not found" error message
 


First you must Convert the InLineShape to a Shape using the ConvertToShape Method.

Skip,

[glasses] [red]Be Advised![/red]
The band of elderly oriental musicians, known as Ground Cover, is, in reality...
Asian Jasmine![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top