locked
Word 2010 Macros do not align objects vertical or horizontal RRS feed

  • Question

  • I word 2007 I have macors that I use on charts inserted from Excel. The macro will set the size, rotate it 90 degrees, center it left to right, center it on the page, and put a border on it.

    This functionality does not work in Word 2010.

    Here is my Word 2007 Macro that I recorded:

    Sub ChartsRotated()
    '
    ' ChartsRotated Macro
    '
    '
        Selection.ShapeRange.Width = 676.8
        Selection.ShapeRange.IncrementRotation -90#
        WordBasic.AlignCenterHorizontal
        WordBasic.AlignCenterVertical
        Selection.ShapeRange.Line.Weight = 1#
        Selection.ShapeRange.Line.Visible = msoTrue
        Selection.ShapeRange.Line.Style = msoLineSingle
    End Sub

    When I recorded the same thing in word 2010 this was the result:

    Sub ChartsRotated()
    '
    ' ChartsRotated Macro
    '
    '

        Selection.ShapeRange.Width = 676.8

        Selection.ShapeRange.IncrementRotation -90#

        Selection.ShapeRange.Line.Weight = 1#

        Selection.ShapeRange.Line.Visible = msoTrue

        Selection.ShapeRange.Line.Style = msoLineSingle

    End Sub

    I did copy the word 2007 version of the macro into Word 2010 and it worked. So, I found a work around. The wordbasic class does not autocomplete, so you just have to know the methods/options. I did try to mess with Selection.ShapeRange.Align msoAlignCenters or msoAlignLefts, but that did nothing.

     

    Wednesday, April 13, 2011 3:35 PM

Answers

  • hi Ken,

    Try:
    Sub ChartsRotated()
    With Selection.ShapeRange
      .Width = 676.8
      .IncrementRotation -90
      .Left = wdShapeCenter
      .Top = wdShapeCenter
      .RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
      .RelativeVerticalPosition = wdRelativeVerticalPositionMargin
      .Line.Weight = 1
      .Line.Visible = msoTrue
      .Line.Style = msoLineSingle
    End With
    End Sub


    Cheers
    Paul Edstein
    [MS MVP - Word]
    • Marked as answer by Nick Wan Monday, April 18, 2011 5:03 AM
    Thursday, April 14, 2011 3:05 AM