Need to set "Wrapping Style Property" of inserted picture.

R

Rick

I'm using the following code to insert a picture in a Word Document,
however, I want the Wrapping Style Property of the picture to be set to
"Behind Text".

Sub Insert_Pic()
ActiveDocument.Shapes.AddPicture FileName:= "C:\MyPicture.bmp", _
LinkToFile:=False, SaveWithDocument:=True, Width:="192",
Height:="59"
End Sub


I have the following code but an not sure how to insert it into my
procedure. Can anyone please help? Thanks.
Applications.Options.PictureWrapType = wdWrapMergeBehind
 
R

Rick

I just realized the code "Applications.Options.PictureWrapType =
wdWrapMergeBehind" effects Word default settings. I just want to change the
PictureWrapType on the inserted picture NOT the program default setting.

Thanks in advance for any help offered. Rick
 
J

Jay Freedman

Hi Rick,

First, you need to declare a Shape object variable within your macro,
and assign the result of the Shapes.AddPicture method to that
variable. Then you can change as many properties of that object as you
like.

Another complication is that -- for reasons known only to some
architect at MS -- Shape objects don't use quite the same syntax to
modify their wrapping as the .PictureWrapType option does. Do it this
way:

Sub Insert_Pic()
' declare a Shape object variable
Dim MyShape As Shape

' store the pointer to the new shape
' (note the Set keyword and parentheses)
Set MyShape = ActiveDocument.Shapes.AddPicture( _
FileName:="C:\clips\4cup.bmp", _
LinkToFile:=False, SaveWithDocument:=True)

' set properties of the Shape object
With MyShape
.Width = 192
.Height = 59
.ZOrder msoSendBehindText
.WrapFormat.Type = wdWrapNone
End With
End Sub
 
R

Rick

Hi Jay,

I wish I understood the Shapes and InlineShapes object collections
better
and the differences between them.

Your code works great in setting the properties correctly, however, the
picture (which is actually my signature) is placed at the top of the
document when my desire is for it to be placed on the line where the cursor
rests.

I was originally using "Selection.InlineShapes" which gave me the proper
insertion point but I wasn't able to change the desired properties. I
altered the
code to "ActiveDocument.Shapes" so that I could at least change the width
and height properties just before I posted the question to the news group
not
realizing in doing so I had lost the insertion point.

If I apply what I've learned from you and change the code back to
"Selection.InlineShapes" the ".ZOrder" and ".WrapFormat.Type" lines
return "Method or data member not found"

============================
Sub Insert_Pic()
' declare an InlineShape object variable
Dim MyShape As InlineShape

' store the pointer to the new shape
Set MyShape =
Selection.InlineShapes.AddPicture(FileName:="C:\MySignature.bmp", _
LinkToFile:=False, SaveWithDocument:=True)

' set properties of the InlineShape object
With MyShape
.Width = 160
.Height = 49
.ZOrder msoSendBehindText
.WrapFormat.Type = wdWrapNone
End With
End Sub
============================

I don't want to take too much of your time, but can the ZOrder and
WrapFormat.Type
properties be changed when using the "Selection" property and "InlineShapes"
object?

I'd also like to change Picture Position > Vertical > Absolute Position
= 0.02" below Paragraph in the code.

Thank you VERY much. Without news groups and talented people like
yourself answering questions us novice programmers would never get anything
to work.
 
J

Jay Freedman

Hi Rick,

Very briefly, an InlineShape object represents a graphic that has a
text wrapping type of "In Line With Text", while a Shape object
represents a graphic with any other wrapping type.

An InlineShape is treated like a single large character -- it's in the
text layer, it can't be dragged around the page, it moves when you
edit the text above or to the left of it, and you can't send it behind
text or in front of text (which is why those two lines in the macro
give you errors). You also can't set its absolute position, because
that's determined by the surrounding text, just as it would be for a
character.

A Shape object "floats" in a drawing layer that's either in front of
or behind the text layer. It can have a WrapFormat (square, tight,
top/bottom, none) and an absolute position.

The reason the picture in the Shape version of the macro went to the
top of the document is that you omitted the optional parameter Anchor
from the AddPicture statement. That parameter specifies the range (the
piece of document) where Word "pins" the picture; if you don't specify
it, Word assumes the beginning of the document.

Covering all those bases, here's a version that should work for you.

Sub Insert_Pic()
' declare an InlineShape object variable
Dim MyShape As Shape

' store the pointer to the new shape
Set MyShape = ActiveDocument.Shapes.AddPicture( _
FileName:="C:\MySignature.bmp", _
LinkToFile:=False, SaveWithDocument:=True, _
Anchor:=Selection.Range)

' set properties of the Shape object
With MyShape
.Width = 160
.Height = 49
.ZOrder msoSendBehindText
.WrapFormat.Type = wdWrapNone
.RelativeHorizontalPosition = _
wdRelativeHorizontalPositionCharacter
.RelativeVerticalPosition = _
wdRelativeVerticalPositionParagraph
.Left = 0
.Top = InchesToPoints(0.02)
End With
End Sub

Regards,
Jay Freedman
Microsoft Word MVP
 

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