Results 1 to 2 of 2

Thread: Macro for text box in Word

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    1

    Macro for text box in Word

    I have a 10 page document with lettered paragraphs in Word. I need a macro that will place a text box in the same paragraph where the cursor is. I recorded the macro, but it sends the text box up to the original paragraph where I created the macro, not where the cursor is at that moment. How can I tell the macro to place the box wherever the cursor is, or at least in the current paragraph?

    Here's the code that Word wrote when I recorded the macro:
    ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 424.8, _
    244.8, 136.8, 158.4).Select
    Selection.ShapeRange.TextFrame.TextRange.Select
    Selection.Collapse
    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 = msoTrue
    Selection.ShapeRange.Line.ForeColor.RGB = RGB(0, 0, 0)
    Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
    Selection.ShapeRange.LockAspectRatio = msoFalse
    Selection.ShapeRange.Height = 158.4
    Selection.ShapeRange.Width = 136.8
    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.Left = InchesToPoints(5.4)
    Selection.ShapeRange.Top = InchesToPoints(0.06)
    Selection.ShapeRange.LockAnchor = True
    Selection.ShapeRange.WrapFormat.Type = wdWrapTopBottom
    Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
    Selection.ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0)
    Selection.ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0)
    Selection.ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
    Selection.ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
    End Sub

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Macro for text box in Word

    Since you are using the uh lovely selection object...
    Code:
    ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 424.8, _
    244.8, 136.8, 158.4).Select
    This is the part you need to look at.

    If you read the helpfiles it should give you an idea where/what it is creating.

    Or the other section:
    Code:
    Selection.ShapeRange.Left = InchesToPoints(5.4)
    Selection.ShapeRange.Top = InchesToPoints(0.06)
    Selection.ShapeRange.LockAnchor = True
    That looks more like positioning, but whether it is relative to your selection object or to the document, I'm not sure.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

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



Click Here to Expand Forum to Full Width