Funny you should ask this now. I was just fighting with the same problem
yesterday. Using the macro recorder whilst changing the text wrapping from In
Front of Text to Behind Text and back again yielded an answer. (BTW, Word
calling it 'text wrapping' is a bit misleading - as you'll soon see. ;-P)
My macro is designed to actually insert an image into a known (bookmarked)
location within a document, but you should be able to modify it to suit by
looping through the Shapes collection.
Private Sub InsertProductImage(ProductID As String)
With ActiveDocument
If .Bookmarks.Exists("Image") = True Then
Dim myRange As Range
Dim myFileName As String
Dim myPicture As Shape
myFileName = "P:\Sales Proposal\Images\" & ProductID & ".jpg"
Set myRange = .Bookmarks("Image").Range
On Error GoTo NoPic
Set myPicture = .Shapes.AddPicture(FileName:=myFileName,
LinkToFile:=False, SaveWithDocument:=True, Anchor:=myRange)
With myPicture
.LayoutInCell = True
.Left = wdShapeCenter
.LockAnchor = True
.LockAspectRatio = msoTrue
.Width = CentimetersToPoints(5)
.Top = CentimetersToPoints(0)
With .WrapFormat
.AllowOverlap = True
.Type = 3
End With
.ZOrder 5
End With
End If
End With
Exit Sub
NoPic:
MsgBox "Unable to find the image for the Product " & ProductID & "." &
vbLf _
& "Please contact (e-mail address removed) for assistance."
End Sub
The really important bits of this that will most likely be of interest to
you are found under the 'With myPicture' statement. This is where all of the
various properties of the image are set, including height, width and, most
importantly, something called ZOrder. It is this last property that sets the
text wrapping to Behind Text. (See why I said it's misleading?)
Note that I use the .Left property to set the horizontal alignment
alignment, but I'm sure there are other ways of doing this. (I can get away
with this method because the image is inserted into a table cell, which
controls the alignment well enough for my purposes.) I also just set the
..Width property and rely on the .LockAspectRatio property to control the
height; you will probably want to do this the other way 'round.
I don't know about adding the TextBox under the image and grouping it with
the image, but since you've already got a Range object and a Shape object to
work with, I can see how it might be done. Check out the .InsertAfter method
for the Range object. You might have to create a TextBox object first... I'm
not really sure, and unfortunately, I don't have time to investigate further
right now. Maybe somebody else has some experience with this and can offer
some advice?
--
Cheers!
Gordon Bentley-Mix
Word MVP
Please post all follow-ups to the newsgroup.
Read the original version of this post in the Office Discussion Groups - no
membership required!