none
Problem with text wrapping when inserting an image into a table RRS feed

  • Question

  • We are having a problem with some of our document automation using Delphi.

    In one scenario we have a document with a table containing images.  This is generated automatically with the images inserted into the 1st column using the following code:

    var
       wordshape: olevariant;   
    
    wordshape := tbl.Cell(row, 1).Range.InlineShapes.AddPicture(s, EmptyParam, EmptyParam, EmptyParam);
       wordshape.LockAspectRatio := msoFalse;
       wordshape.Width := SetWidth(50);
       wordshape.Height := SetWidth(40);

    This works fine, apart from the Wrap Text settings ignoring the system default.  Images insert with Wrap Text set to Inline with text when we want them to be set to Tight.

    Is there a simple way to set the WrapText property for an image inserted into a table?

    Thanks

    Dan


    Dan Kelly
    Wednesday, May 11, 2011 1:14 PM

Answers

  • Dan,

    I think what occurs when you manually change the wrap setting from the ribbon is it first converts the shape and then formats it with the wrap setting.

    An inline shape cannot have a wrap setting.

     


    Regards, Rich
    Friday, May 13, 2011 1:54 PM

All replies

  • Hi Dan,

    Here is the code used to convert an inline shape to a floating shape and then setting the text wrapping.

      Selection.InlineShapes(1).ConvertToShape
      Selection.ShapeRange.WrapFormat.Type = wdWrapTight

    Whether the floating shape will anchor itself consistently in your table cell, I cannot say.

    Hope this helps


    Regards, Rich
    Wednesday, May 11, 2011 2:29 PM
  • Rich

    Thanks for the suggestion.

    Unfortunately, as you suggested, the conversion does seem to unpin the image from the table, which isn't what we need.

    (Normally I'd get a suggestion by recording a macro, but I don't seem to be able to change the wrap settings on an image in a table whilst macros are recording in 2010.)

    Any other suggestions?

    Dan


    Dan Kelly
    Thursday, May 12, 2011 1:36 PM
  • Hi Dan,

    Well AFAIK that's pretty much your only option. Wrapping text only applies to floating shapes. There is an option for an Anchor Lock on a floating shape, so maybe that's something for you to experiment with.

    I did try a test with putting an image in a text box and it will "only" allow in-line shapes.

    As for recording macros, many functions, formatting pictures being one, cannot be recorded. This is not new to 2010, Office 2003 and 2007 didn't provide for it either. The Office Developer Reference is another source for coding examples.

    Hope this helps


    Regards, Rich
    Thursday, May 12, 2011 7:00 PM
  • Hmph.

    Wrapping settings are certainly available manually for images pasted into a table, so why wouldn't they be available to VBA?

    Cutting out recording of macros is going to a real problem for us as that's a major part of how translate to Delphi

    Thanks Rich

    Dan


    Dan Kelly
    Friday, May 13, 2011 1:38 PM
  • Dan,

    I think what occurs when you manually change the wrap setting from the ribbon is it first converts the shape and then formats it with the wrap setting.

    An inline shape cannot have a wrap setting.

     


    Regards, Rich
    Friday, May 13, 2011 1:54 PM