Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Shape at current cursor position in Word

Status
Not open for further replies.

ninjamyst

Programmer
Jan 28, 2005
21
US
Hi. I am trying to insert a rectangle shape right after the current cursor. I know you can do ActiveDocument.Shapes.AddShape() but how do I find the current position of the cursor? I need to specify the "Left" and "Top" of the rectangle which should be where the cursor currently is. Also how can I find the width of the page? I want the rectangle to fill up the width of the page with a constant height. I wish the Selection object has an Shapes.AddShape method but it only has InlineShape.AddPicture.
 
Hi ninjamyst,

To get the current horizontal position you could use:
Selection.Information(wdHorizontalPositionRelativeToPage)

As for the rest, the following should get you started:
Code:
Sub Test()
Dim oPrintWidth
Dim oShpWidth
Dim oShpHght
Dim oShpTop
Dim oShpLeft
With ActiveDocument
    With .PageSetup
        oPrintWidth = .PageWidth - .LeftMargin - .RightMargin - .Gutter
    End With
    oShpWidth = oPrintWidth
    oShpHght = oPrintWidth / 2
    oShpTop = 0
    oShpLeft = 0
    .Shapes.AddShape(msoShapeFlowchartExtract, 0, 0, oShpWidth, oShpHght).Select
    With Selection.ShapeRange
        .Rotation = 0#
        .RelativeHorizontalPosition = wdRelativeHorizontalPositionCharacter
        .RelativeVerticalPosition = wdRelativeVerticalPositionLine
        .Left = oShpTop
        .Top = oShpLeft
    End With
End With
End Sub
You'll see I've defined variables for oPrintWidth, oShpWidth, oShpHght, oShpTop & oShpLeft. I'll leave you to decide what the real values for each of these should be and how to calculate them.


Cheers



[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top