Add a Floating Shape Anchored to Current Paragraph

L

Larry Lutz

I need to set up a macro that will always add a picture as a floating shape
anchored to the current paragraph (where the cursor is located at the time
the function executes). The picture would always be the same file in the
same location. For the life of me, I can't figure out how to do it using the
Help on VBA in Word. I'm currently using Word 2003, but I need for this
macro to work in Word 2000.

The following code is as close as I could get, but it obviously doesn't
accomplish the part about anchoring to the current paragraph:

Dim myPicture As Shape

With ActiveDocument.Shapes
Set myPicture = .AddPicture("E:\Documents and Settings\My
Documents\My Pictures\test.jpg", _
Linktofile = False, Savewithdcoument = True)
With myPicture.WrapFormat
.Type = wdWrapSquare
.Side = wdWrapRight
End With
ActiveDocument.Shapes("myPicture").Anchor.Paragraphs(1).Range.Select
End With

Any help will be most appreciated.

Larry
 
T

Tony Jollans

Hi Larry,

You want to anchor the picture when you first pull it in ..

Set myPicture = .AddPicture("E:\Documents and Settings\My Documents\My
Pictures\test.jpg", _
Linktofile = False, Savewithdcoument = True, _
Anchor :=Selection.Range)

You might want to anchor it more specifically to the begining of the
paragraph or something, I don't know, but that change will anchor it at the
cursor.

Also lose the ...Shapes("myPicture").Anchor.... line at the end; even if
corrected it is not needed.
 
L

Larry Lutz

That worked perfectly! Thanks.

Larry
Tony Jollans said:
Hi Larry,

You want to anchor the picture when you first pull it in ..

Set myPicture = .AddPicture("E:\Documents and Settings\My Documents\My
Pictures\test.jpg", _
Linktofile = False, Savewithdcoument = True, _
Anchor :=Selection.Range)

You might want to anchor it more specifically to the begining of the
paragraph or something, I don't know, but that change will anchor it at
the
cursor.

Also lose the ...Shapes("myPicture").Anchor.... line at the end; even if
corrected it is not needed.
 

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