InlineShapes Absolute Position in document

J

Jeff Mathewson

Hello all,

I'm trying to convert some object images to Inlineshapes images in Word
20007 but I can't seem to find the properties to set the TOP /LEFT position
of the picture. Anyone have ideas? I found using Shape() doesn’t work..I
need to work with the InlineShapes which doesn’t seem to have the needed
properties.

Thanks for any help

Jeff.
 
J

Jay Freedman

InlineShapes don't have Top and Left properties precisely because
their position is determined by where they fall within the text --
exactly as if they were simply a big character.

If you need an exact position on the page, you _must_ use a Shape
object. What about a Shape "doesn't work"?

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
J

Jeff Mathewson

Thanks for you reply,

The problem that I'm having is when I convert the image object to a shape
object the Shape Object floots over the text. And if I convert the Shape
Object so I can place it anywhere within a page, I noted that the Shape
Object turns into a InlineShape Object or at least that's what VBA thinks it
is??? So I'm hoping there is some way to set the location of the picture on
the page using VBA without the use of the mouse to drag it. :)

Thanks for any help you can give.

Jeff.
 
J

Jay Freedman

The key to placing a Shape object precisely is to define its Anchor,
which is a Range object within the text. Then the Top and Left
properties are measured from that anchor point. If you fail to define
an anchor, VBA assumes you meant to place it at the top left corner of
the page, which is almost never correct.

Here's some sample code for placing a Shape 0.5 inch to the right and
0.1 inch above the current cursor location, and then sizing the Shape
and setting its wrapping to Square:

Sub demo()
Dim oShp As Shape
Dim oRg As Range

Set oRg = Selection.Range
oRg.Collapse wdCollapseStart

Set oShp = ActiveDocument.Shapes.AddPicture( _
FileName:="C:\bunnycakes.jpg", _
LinkToFile:=False, _
SaveWithDocument:=True, _
Left:=InchesToPoints(0.5), _
Top:=InchesToPoints(-0.1), _
Anchor:=oRg)
' Left and Top are relative to the anchor

With oShp
.WrapFormat.Type = wdWrapSquare
.LockAspectRatio = msoTrue
.Width = InchesToPoints(2.5)
End With
End Sub

Variations on this would be to define the range differently, to make
the Shape by calling the .ConvertToShape method of an existing
InlineShape, resizing the .Width and .Height separately, etc.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top