Setting Picture Layout Wrapping Style with Macro

Discussion in 'Word VBA' started by Michael Goerz, Nov 18, 2007.

  1. Hi,

    I have a document with with a number of pictures, for each of which I
    want to set the Layout options to have them floating properly. Doing
    this by hand requires to go to the Image Properties, to the Layout Tab,
    go to Advanced, and set some options both in the Picture Position and
    Text Wrapping tab. So, it's quite a few clicks, and I was hoping I could
    put it all together as a macro, so that I just have to select a picture
    an hit a shortcut to set all the options as I want them.

    Unfortunately, it doesn't seem I can put the actions in a macro. When
    the macro recorder is started, I can't do a right click on the image,
    and even if I go through the 'Format' menu and the to 'Picture', all the
    relevant options are inaccessible (grayed out). Is there a way to put
    the Wrapping Style options in a Macro?

    Thanks,
    Michael Goerz
     
    Michael Goerz, Nov 18, 2007
    #1
    1. Advertisements

  2. Michael Goerz

    Jay Freedman Guest

    Hi Michael,

    You can write such a macro in the VBA editor, you just can't do it
    through the recorder.

    If you describe the exact settings you want to use, we can tell you
    what code to write.

    On Sun, 18 Nov 2007 20:58:30 +0100, Michael Goerz
    <4ward.com> wrote:

    >Hi,
    >
    >I have a document with with a number of pictures, for each of which I
    >want to set the Layout options to have them floating properly. Doing
    >this by hand requires to go to the Image Properties, to the Layout Tab,
    >go to Advanced, and set some options both in the Picture Position and
    >Text Wrapping tab. So, it's quite a few clicks, and I was hoping I could
    >put it all together as a macro, so that I just have to select a picture
    >an hit a shortcut to set all the options as I want them.
    >
    >Unfortunately, it doesn't seem I can put the actions in a macro. When
    >the macro recorder is started, I can't do a right click on the image,
    >and even if I go through the 'Format' menu and the to 'Picture', all the
    >relevant options are inaccessible (grayed out). Is there a way to put
    >the Wrapping Style options in a Macro?
    >
    >Thanks,
    >Michael Goerz


    --
    Regards,
    Jay Freedman
    Microsoft Word MVP
    Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
     
    Jay Freedman, Nov 19, 2007
    #2
    1. Advertisements

  3. Jay Freedman wrote:
    > Hi Michael,
    >
    > You can write such a macro in the VBA editor, you just can't do it
    > through the recorder.
    >
    > If you describe the exact settings you want to use, we can tell you
    > what code to write.

    Doing it manually in Word 2003, I would choose the following settings in
    the Advanced Layout dialog (at Format>Picture>Layout>Advanced):

    In the 'Text Wrapping' tab:
    Wrapping Style: Top and bottom
    Distance from text: Top 0.2"
    Bottom 0.2"

    In the 'Picture Position' tab:
    Horizontal Alignment: Centered relative to Page

    All other values should stay whatever they are.

    Thanks,
    Michael
     
    Michael Goerz, Nov 19, 2007
    #3
  4. Michael Goerz

    Jay Freedman Guest

    OK, here you go...

    Sub FormatMyPicture()
    Dim myShape As Shape

    If Selection.InlineShapes.Count > 0 Then
    Set myShape = Selection.InlineShapes(1).ConvertToShape
    ElseIf Selection.ShapeRange.Count > 0 Then
    Set myShape = Selection.ShapeRange(1)
    Else
    MsgBox "Please select a picture first."
    Exit Sub
    End If

    With myShape
    .WrapFormat.Type = wdWrapTopBottom
    .WrapFormat.DistanceTop = InchesToPoints(0.2)
    .WrapFormat.DistanceBottom = InchesToPoints(0.2)
    .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
    .Left = wdShapeCenter
    End With
    End Sub

    The first group of statements makes sure there is a picture (or an
    AutoShape or WordArt) selected, and if it's in line with text it
    converts it to a floating shape. The second group of statements
    applies the formatting you specified.

    On Mon, 19 Nov 2007 23:41:26 +0100, Michael Goerz
    <4ward.com> wrote:

    >Jay Freedman wrote:
    >> Hi Michael,
    >>
    >> You can write such a macro in the VBA editor, you just can't do it
    >> through the recorder.
    >>
    >> If you describe the exact settings you want to use, we can tell you
    >> what code to write.

    >Doing it manually in Word 2003, I would choose the following settings in
    >the Advanced Layout dialog (at Format>Picture>Layout>Advanced):
    >
    >In the 'Text Wrapping' tab:
    >Wrapping Style: Top and bottom
    >Distance from text: Top 0.2"
    > Bottom 0.2"
    >
    >In the 'Picture Position' tab:
    >Horizontal Alignment: Centered relative to Page
    >
    >All other values should stay whatever they are.
    >
    >Thanks,
    >Michael


    --
    Regards,
    Jay Freedman
    Microsoft Word MVP
    Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
     
    Jay Freedman, Nov 20, 2007
    #4
  5. Jay Freedman wrote:
    > OK, here you go...
    >
    > Sub FormatMyPicture()
    > Dim myShape As Shape
    >
    > If Selection.InlineShapes.Count > 0 Then
    > Set myShape = Selection.InlineShapes(1).ConvertToShape
    > ElseIf Selection.ShapeRange.Count > 0 Then
    > Set myShape = Selection.ShapeRange(1)
    > Else
    > MsgBox "Please select a picture first."
    > Exit Sub
    > End If
    >
    > With myShape
    > .WrapFormat.Type = wdWrapTopBottom
    > .WrapFormat.DistanceTop = InchesToPoints(0.2)
    > .WrapFormat.DistanceBottom = InchesToPoints(0.2)
    > .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
    > .Left = wdShapeCenter
    > End With
    > End Sub
    >
    > The first group of statements makes sure there is a picture (or an
    > AutoShape or WordArt) selected, and if it's in line with text it
    > converts it to a floating shape. The second group of statements
    > applies the formatting you specified.

    Cool!
    Thanks so much!

    Michale
     
    Michael Goerz, Nov 20, 2007
    #5
  6. Michael Goerz

    gzep Guest

    Hi Jay,

    I had the same question, so you answer has helped me too!

    I find that the .ConvertToShape makes the object no longer an inline object,
    and thus does not stay anchored to the position in the text where it was
    pasted.

    If I use the .ConvertToInlineShape, the formatting that I just applied gets
    removed. Then I'm back to square 1.

    if I convertToInlineShape, then format I get: "Object has been deleted"!

    Any thoughts on how to make it inline again, and retain the formatting?

    "Jay Freedman" wrote:

    > OK, here you go...
    >
    > Sub FormatMyPicture()
    > Dim myShape As Shape
    >
    > If Selection.InlineShapes.Count > 0 Then
    > Set myShape = Selection.InlineShapes(1).ConvertToShape
    > ElseIf Selection.ShapeRange.Count > 0 Then
    > Set myShape = Selection.ShapeRange(1)
    > Else
    > MsgBox "Please select a picture first."
    > Exit Sub
    > End If
    >
    > With myShape
    > .WrapFormat.Type = wdWrapTopBottom
    > .WrapFormat.DistanceTop = InchesToPoints(0.2)
    > .WrapFormat.DistanceBottom = InchesToPoints(0.2)
    > .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
    > .Left = wdShapeCenter
    > End With
    > End Sub
    >
    > The first group of statements makes sure there is a picture (or an
    > AutoShape or WordArt) selected, and if it's in line with text it
    > converts it to a floating shape. The second group of statements
    > applies the formatting you specified.
    >
    > On Mon, 19 Nov 2007 23:41:26 +0100, Michael Goerz
    > <4ward.com> wrote:
    >
    > >Jay Freedman wrote:
    > >> Hi Michael,
    > >>
    > >> You can write such a macro in the VBA editor, you just can't do it
    > >> through the recorder.
    > >>
    > >> If you describe the exact settings you want to use, we can tell you
    > >> what code to write.

    > >Doing it manually in Word 2003, I would choose the following settings in
    > >the Advanced Layout dialog (at Format>Picture>Layout>Advanced):
    > >
    > >In the 'Text Wrapping' tab:
    > >Wrapping Style: Top and bottom
    > >Distance from text: Top 0.2"
    > > Bottom 0.2"
    > >
    > >In the 'Picture Position' tab:
    > >Horizontal Alignment: Centered relative to Page
    > >
    > >All other values should stay whatever they are.
    > >
    > >Thanks,
    > >Michael

    >
    > --
    > Regards,
    > Jay Freedman
    > Microsoft Word MVP
    > Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
    >
     
    gzep, Dec 6, 2007
    #6
  7. Michael Goerz

    Jay Freedman Guest

    First, recognize that there are properties of Shape objects that
    simply don't make sense for InlineShape objects, and vice versa. In
    particular, all of the properties listed in the With clause of the
    macro below can be applied to a Shape object, but are not defined for
    an InlineShape object, which simply has no place to store that
    information because it doesn't need it.

    An InlineShape object behaves like a single character, so its position
    is determined by the characters before it in the text. It has no use
    for a WrapFormat property, a Left or Top property, and so on. Those
    things apply only to Shape objects, which need them to determine
    position on the page.

    When you call ConvertToInlineShape, VBA simply discards all of the
    Shape properties that don't apply to an InlineShape. Similarly, when
    you call ConvertToShape, VBA discards any InlineShape properties that
    don't apply to a Shape. You can see which these are by comparing the
    lists of properties in the Help topics for the two kinds of objects.

    Second, with respect to "ConvertToShape makes the object no longer an
    inline object": Exactly. That's the whole point of calling the method!
    Be very careful about the concept of "anchored" for a Shape object,
    though. The "anchor" is the top left corner of the paragraph that
    contained the insertion point at the time the Shape was created,
    unless (a) you use the optional Anchor parameter of the .Add method to
    specify a different range or (b) you later drag the anchor to a
    different paragraph. Then the position of the Shape with respect to
    that anchor point is specified by the .Left and .Top properties, as
    modified by the .RelativeHorizontalPosition and
    ..RelativeVerticalPosition properties. You may have to read the Help a
    few times and experiment a bit, but you'll be rewarded by being able
    to control the shape's position. Then you won't have to worry about
    converting to an InlineShape and losing formatting that it can't have.

    On Wed, 5 Dec 2007 21:33:01 -0800, gzep
    <> wrote:

    >Hi Jay,
    >
    >I had the same question, so you answer has helped me too!
    >
    >I find that the .ConvertToShape makes the object no longer an inline object,
    >and thus does not stay anchored to the position in the text where it was
    >pasted.
    >
    >If I use the .ConvertToInlineShape, the formatting that I just applied gets
    >removed. Then I'm back to square 1.
    >
    >if I convertToInlineShape, then format I get: "Object has been deleted"!
    >
    >Any thoughts on how to make it inline again, and retain the formatting?
    >
    >"Jay Freedman" wrote:
    >
    >> OK, here you go...
    >>
    >> Sub FormatMyPicture()
    >> Dim myShape As Shape
    >>
    >> If Selection.InlineShapes.Count > 0 Then
    >> Set myShape = Selection.InlineShapes(1).ConvertToShape
    >> ElseIf Selection.ShapeRange.Count > 0 Then
    >> Set myShape = Selection.ShapeRange(1)
    >> Else
    >> MsgBox "Please select a picture first."
    >> Exit Sub
    >> End If
    >>
    >> With myShape
    >> .WrapFormat.Type = wdWrapTopBottom
    >> .WrapFormat.DistanceTop = InchesToPoints(0.2)
    >> .WrapFormat.DistanceBottom = InchesToPoints(0.2)
    >> .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
    >> .Left = wdShapeCenter
    >> End With
    >> End Sub
    >>
    >> The first group of statements makes sure there is a picture (or an
    >> AutoShape or WordArt) selected, and if it's in line with text it
    >> converts it to a floating shape. The second group of statements
    >> applies the formatting you specified.
    >>
    >> On Mon, 19 Nov 2007 23:41:26 +0100, Michael Goerz
    >> <4ward.com> wrote:
    >>
    >> >Jay Freedman wrote:
    >> >> Hi Michael,
    >> >>
    >> >> You can write such a macro in the VBA editor, you just can't do it
    >> >> through the recorder.
    >> >>
    >> >> If you describe the exact settings you want to use, we can tell you
    >> >> what code to write.
    >> >Doing it manually in Word 2003, I would choose the following settings in
    >> >the Advanced Layout dialog (at Format>Picture>Layout>Advanced):
    >> >
    >> >In the 'Text Wrapping' tab:
    >> >Wrapping Style: Top and bottom
    >> >Distance from text: Top 0.2"
    >> > Bottom 0.2"
    >> >
    >> >In the 'Picture Position' tab:
    >> >Horizontal Alignment: Centered relative to Page
    >> >
    >> >All other values should stay whatever they are.
    >> >
    >> >Thanks,
    >> >Michael


    --
    Regards,
    Jay Freedman
    Microsoft Word MVP
    Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
     
    Jay Freedman, Dec 7, 2007
    #7
  8. Michael Goerz

    Guest

    Hi Jay,

    I want to select multiple objects at one time and then apply the formatting (wrapping) . Can you help me with that ? Instead of selecting one image at one time and running the macro?

    Secondly, I am trying to write a macro wherein I Can directly import more than One objects into the Document file and I want them to be shifted anywhere in the screen.

    On Monday, 19 November 2007 01:28:30 UTC+5:30, Michael Goerz wrote:
    > Hi,
    >
    > I have a document with with a number of pictures, for each of which I
    > want to set the Layout options to have them floating properly. Doing
    > this by hand requires to go to the Image Properties, to the Layout Tab,
    > go to Advanced, and set some options both in the Picture Position and
    > Text Wrapping tab. So, it's quite a few clicks, and I was hoping I could
    > put it all together as a macro, so that I just have to select a picture
    > an hit a shortcut to set all the options as I want them.
    >
    > Unfortunately, it doesn't seem I can put the actions in a macro. When
    > the macro recorder is started, I can't do a right click on the image,
    > and even if I go through the 'Format' menu and the to 'Picture', all the
    > relevant options are inaccessible (grayed out). Is there a way to put
    > the Wrapping Style options in a Macro?
    >
    > Thanks,
    > Michael Goerz
     
    , Dec 11, 2013
    #8
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. mc
    Replies:
    4
    Views:
    243
    Chuck
    Apr 22, 2005
  2. Rick
    Replies:
    4
    Views:
    524
    Jay Freedman
    Jun 15, 2005
  3. Beth Brooks
    Replies:
    2
    Views:
    136
    Beth Brooks
    Feb 10, 2006
  4. reclusive monkey

    Recording text wrapping layout options macro

    reclusive monkey, May 22, 2008, in forum: Word VBA
    Replies:
    1
    Views:
    257
    Jay Freedman
    May 23, 2008
  5. ksay85
    Replies:
    1
    Views:
    227
    Gordon Bentley-Mix on news.microsoft.com
    Nov 19, 2009
  6. BulionCuBranza
    Replies:
    1
    Views:
    152
    Fumei2 via OfficeKB.com
    Feb 9, 2010
  7. dedawson
    Replies:
    9
    Views:
    934
    Stefan Blom
    Oct 4, 2010
  8. dedawson
    Replies:
    0
    Views:
    482
    dedawson
    Sep 29, 2010
Loading...