Writting a VBA to draw line

I would like to know how to write a macro in VBA for msword 2007 such that by activating the macro (through assigning a hotkey), I can activate the same draw line function as in Insert -> Shape -> Line. This is because at times, I need to draw a shape with many lines and using Insert -> Shape -> Line is too time-consuming.
Currently, my drawline macro is

Sub drawline()
   SendKeys ("%nsh"), True
   SendKeys ("{DOWN}{DOWN}{ENTER}"), True
End Sub

The above macro activate the keypress Insert -> Shape -> Line.
Is there a more straightforward way.
The line inserted must have a starting point at the cursor position, same effect as
Insert -> Shape -> Line.
Thank you.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

activedocument.Shapes.AddLine 50, 50, 100, 100
twowheelAuthor Commented:
But I do not want my line to have a fixed starting point, I want it to be at the cursor position and the end point can be dragged before the line is drawn.
that is the line of code that you would put in your macro...  the numbers are the start and end points of the line as plotted on an x-y chart.

You should add to this and explore a bit using intellisense...
Macro showing intellisense
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

well you can change the start point so they equate to the selection co-ordinates...

Sub DrawLine()

Dim oLine As Word.Shape
Dim x As Single
Dim y As Single

x = Selection.Information(wdHorizontalPositionRelativeToPage)
y = Selection.Information(wdVerticalPositionRelativeToPage)

Set oLine = ActiveDocument.Shapes.AddLine(x, y, x + 100, y + 100)

With oLine
            ' start a new line of code in here with a .
            ' the . becomes short hand for 'oLine.'
            ' in here - I mean in this 'with' block

End With


End Sub

Open in new window

twowheelAuthor Commented:
Sorry, I think I have made a mistake in my original question.
What I meant is that
The line inserted must have a starting point as the mouse position (not cursor position),
so that when I left click, I can drag to determine the end point of the line.
Same effect as Insert -> Shape -> Line.
Please refer to the attached docx.

I am not sure how to do that ...
After a bit of searching I found this ... basically you need some VBA to detect the mouse position - I don't think that is going to be easy, and it might not be possible.

However I believe it is possible in XL if that helps...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.