• Formatting a Picture in Word (VBA / Word)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Formatting a Picture in Word (VBA / Word)

    Author
    Topic
    #374641

    I am trying to programically format a picture in Word with no success. Here are the steps I am taking;

    First I insert a *.tif into a Word Document. Then select ‘Format | Picture | Layout’ select ‘Tight and click Left’. This works fine when done manually, but when I try to record these steps, the ‘Wrapping Style’ Options are greyed out.

    Next when I tried the following code on the unformatted *.tif, Word generages the error “4198”, Command Failed;

    Selection.ShapeRange.WrapFormat.Type = wdWrapTight
    Selection.ShapeRange.Left = wdShapeLeft
    Selection.ShapeRange.Top = InchesToPoints(0)

    Any Ideas on how this can be done in a Macro?

    Thank you
    Roland Thomas

    Viewing 0 reply threads
    Author
    Replies
    • #606712

      The instruction
      Selection.ShapeRange.Left = wdShapeLeft
      seems strange to me. You set the left position of the shape to a (non-existing?) Word VBA constant. If you want text to wrap to the left of the shape, you need to use
      Selection.ShapeRange.WrapFormat.Side = wdWrapLeft

      Here is what I got when recording Format/Picture. The only thing I changed was to use With Selection.ShapeRange … End With in order to avoid endless repetition. (Note: my system is set to metric, so I get CentimetersToPoints instead of InchesToPoints.)

      With Selection.ShapeRange
      .Fill.Visible = msoFalse
      .Fill.Transparency = 0#
      .Line.Weight = 0.75
      .Line.DashStyle = msoLineSolid
      .Line.Style = msoLineSingle
      .Line.Transparency = 0#
      .Line.Visible = msoFalse
      .LockAspectRatio = msoTrue
      .Height = 118.2
      .Width = 453.55
      .PictureFormat.Brightness = 0.5
      .PictureFormat.Contrast = 0.5
      .PictureFormat.ColorType = msoPictureAutomatic
      .PictureFormat.CropLeft = 0#
      .PictureFormat.CropRight = 0#
      .PictureFormat.CropTop = 0#
      .PictureFormat.CropBottom = 0#
      .RelativeHorizontalPosition = _
      wdRelativeHorizontalPositionColumn
      .RelativeVerticalPosition = _
      wdRelativeVerticalPositionParagraph
      .Left = CentimetersToPoints(3)
      .Top = CentimetersToPoints(0)
      .LockAnchor = False
      .WrapFormat.Type = wdWrapTight
      .WrapFormat.Side = wdWrapLeft
      .WrapFormat.DistanceTop = CentimetersToPoints(0)
      .WrapFormat.DistanceBottom = CentimetersToPoints(0)
      .WrapFormat.DistanceLeft = CentimetersToPoints(0.32)
      .WrapFormat.DistanceRight = CentimetersToPoints(0.32)
      End With

    Viewing 0 reply threads
    Reply To: Formatting a Picture in Word (VBA / Word)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: