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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie needs help with Rectangle position in Word

Status
Not open for further replies.

tecnik

Programmer
Feb 16, 2006
22
GB
Hi there,

I have a simple macro that draws a rectangle on the page however I'd like to change the macro so it draws the rectangle at the cursor postition. Is this relatively easy to do.

Thanks in advance,

Nick


Here's the code:-
Code:
Sub box()
 ActiveDocument.Shapes.AddShape msoShapeRectangle, 50, 50, 100, 200
End Sub
 
Make it an InlineShape rather than a Shape. InlineShapes are at the cursor position.

Alternatively you CAN position a Shape via code, but it sure is weird doing so.

Gerry
 
Hi Gerry,

Thanks for the help.

I've had a look at the inline shape object and I'm not sure if it'll do what I want.

In the MSDN library it says that in only works with a 'picture, linked picture, embedded OLE object, linked OLE object, or ActiveX control'. Being a newbie on this subject I'm not sure if a rectangle comes under one of these categories?

Regards,

Nick
 
Taking this one step further, I've added the drawing of a line to my original code. What I've been trying to find out now is how I can select the rectangle that was drawn before the line, so basically both the line and the rectangle are selected.

Thanks in advance,

Nick

Here's the code:-

Code:
Sub box2()
'
' picFiveWide Macro
' Macro recorded 17/02/2006 by nhearn
'
    ' Draw Rectangle
    ActiveDocument.Shapes.AddShape(msoShapeRectangle, 50, 50, 100, 100).Select
    Selection.ShapeRange.line.ForeColor.RGB = RGB(255, 0, 0)
    Selection.ShapeRange.line.Visible = msoTrue
    
    ' Draw Line
    ActiveDocument.Shapes.AddLine(150#, 100#, 300#, 100#).Select
    Selection.ShapeRange.Fill.Transparency = 0#
    Selection.ShapeRange.line.Weight = 1#
    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(255, 0, 0)
    Selection.ShapeRange.line.BackColor.RGB = RGB(255, 255, 255)
    
End Sub
 
I have to ask why you are trying to do this.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top