• Macro Frustration (Word 2007)

    • This topic has 5 replies, 2 voices, and was last updated 17 years ago.
    Author
    Topic
    #450937

    Hi All,

    I’m hoping someone cam help me with this–I think it’s a simple problem, but I’m VB illiterate .

    I’ve recorded variations of the macro below several times and none of them will run – I always get the same error message “Runtime error -2147024809 (80070057) – The item with the specified name wasn’t found.”

    When I look at the code, I can see the problem, but can’t understand it. I don’t understand why the text box I’m trying to format has a number assigned to it. More importantly, I don’t know how to modify the code so it will work on any text box I wish to format.

    The macro is below…

    Any help is greatly appreciated!! Thanks in advance…
    Bill

    Sub FormTextBox()

    ‘ FormTextBox Macro


    ActiveDocument.Shapes(“Text Box 69”).Select <—- This is where the macro halts
    Selection.ShapeRange.Fill.Visible = msoTrue
    Selection.ShapeRange.Fill.Solid
    Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 255, 255)
    Selection.ShapeRange.Fill.Transparency = 0#
    Selection.ShapeRange.Line.Weight = 0.75
    Selection.ShapeRange.Line.DashStyle = msoLineSolid
    Selection.ShapeRange.Line.Style = msoLineSingle
    Selection.ShapeRange.Line.Transparency = 0#
    Selection.ShapeRange.Line.Visible = msoFalse
    Selection.ShapeRange.LockAspectRatio = msoFalse
    Selection.ShapeRange.Left = 187.2
    Selection.ShapeRange.Top = 432.7
    Selection.ShapeRange.TextFrame.MarginLeft = 7.2
    Selection.ShapeRange.TextFrame.MarginRight = 7.2
    Selection.ShapeRange.TextFrame.MarginTop = 3.6
    Selection.ShapeRange.TextFrame.MarginBottom = 3.6
    Selection.ShapeRange.RelativeHorizontalPosition = _
    wdRelativeHorizontalPositionColumn
    Selection.ShapeRange.RelativeVerticalPosition = _
    wdRelativeVerticalPositionParagraph
    Selection.ShapeRange.RelativeHorizontalSize = _
    wdRelativeHorizontalSizeMargin
    Selection.ShapeRange.RelativeVerticalSize = wdRelativeVerticalSizeMargin
    Selection.ShapeRange.Left = wdShapeCenter
    Selection.ShapeRange.LeftRelative = wdShapePositionRelativeNone
    Selection.ShapeRange.Top = InchesToPoints(0)
    Selection.ShapeRange.TopRelative = wdShapePositionRelativeNone
    Selection.ShapeRange.WidthRelative = wdShapeSizeRelativeNone
    Selection.ShapeRange.HeightRelative = wdShapeSizeRelativeNone
    Selection.ShapeRange.LockAnchor = False
    Selection.ShapeRange.LayoutInCell = True
    Selection.ShapeRange.WrapFormat.AllowOverlap = True
    Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
    Selection.ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0.1)
    Selection.ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0.1)
    Selection.ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
    Selection.ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
    Selection.ShapeRange.WrapFormat.Type = wdWrapTopBottom
    Selection.ShapeRange.TextFrame.AutoSize = True
    Selection.ShapeRange.TextFrame.WordWrap = True
    Selection.ShapeRange.TextFrame.VerticalAnchor = msoAnchorTop
    End Sub

    Viewing 0 reply threads
    Author
    Replies
    • #1109013

      If you remove the line

      ActiveDocument.Shapes(“Text Box 69”).Select

      the macro will act on the currently selected text box. But keep in mind that if you run it for several text boxes, it will position the text boxes on top of each other.

      • #1109016

        Hi Hans,

        Thanks for the input – it worked as you said it would. Is there a way to make the macro work on just the selected text box? I don’t understand why I get the error noted when I try to run the macro after recording. Thanks in advance for your help–it’s really appreciated!

        Bill

        • #1109017

          Each text box has a unique name, by default the first created in a document is named “Text Box 1”, the next one “Text Box 2”, etc.

          If you select the text box *after* you start recording, the action of selecting that specific text box is included in the macro. Each time you run the macro, it will try to select that specific text box again.
          So you should either select the text box *before* you start recording, or remove the line that selects the text box afterwards, when you’ve finished recording.

          After that the macro will operate on whatever text box you select before running the macro.

          • #1109040

            Thanks Hans, that worked.

            One more question if I may. Though the macro works, it bounces me back to the first text box that appears in the document every time I run it. Apparently it needs the text box ID to operate on just the specified text box? If that’s the case, then I’m back to where I started. Anyway, many thanks for your help. It is much appreciated!

            Regards,
            Bill

            • #1109041

              The macro moves the selected text box to the top. If you don’t want that, you should remove the lines that change the Top and Left properties and the position of the text box.
              I have no idea what you want the macro to do, so without more information I can’t tell you exactly which lines to keep and which ones to remove.

    Viewing 0 reply threads
    Reply To: Macro Frustration (Word 2007)

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

    Your information: