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
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.