Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    Jun 2002
    Location
    New Hampshire
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro Frustration (Word 2007)

    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

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro Frustration (Word 2007)

    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.

  3. #3
    Lounger
    Join Date
    Jun 2002
    Location
    New Hampshire
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro Frustration (Word 2007)

    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

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro Frustration (Word 2007)

    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.

  5. #5
    Lounger
    Join Date
    Jun 2002
    Location
    New Hampshire
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro Frustration (Word 2007)

    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

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro Frustration (Word 2007)

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •