Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rick - 13 Jun 2005 23:04 GMT
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
Rick - 14 Jun 2005 00:18 GMT
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

> 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
[quoted text clipped - 9 lines]
> procedure.  Can anyone please help?  Thanks.
>         Applications.Options.PictureWrapType = wdWrapMergeBehind
Jay Freedman - 14 Jun 2005 03:34 GMT
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

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org

>I just realized the code "Applications.Options.PictureWrapType =
>wdWrapMergeBehind" effects Word default settings.  I just want to change the
[quoted text clipped - 15 lines]
>> procedure.  Can anyone please help?  Thanks.
>>         Applications.Options.PictureWrapType = wdWrapMergeBehind
Rick - 14 Jun 2005 17:34 GMT
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.

Signature

Rick

> Hi Rick,
>
[quoted text clipped - 51 lines]
> >> procedure.  Can anyone please help?  Thanks.
> >>         Applications.Options.PictureWrapType = wdWrapMergeBehind
Jay Freedman - 15 Jun 2005 04:11 GMT
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                 FAQ: http://word.mvps.org

>Hi Jay,
>
[quoted text clipped - 50 lines]
>yourself answering questions us novice programmers would never get anything
>to work.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.