Solved

VBA: Make Horizontal Line on MS WORD document

Posted on 1998-11-16
2
1,778 Views
Last Modified: 2013-02-26
I wanted to make a MS Word Marco (VBA) for a MS Word Icon, which will make a horizontal line on the MS Word document, the line require:

1. The row position is the current cursor position.
2. The Length is the Page Width - Left Margin - Rigth Margin

Do you know how to make this?

Thanks a lot.
0
Comment
Question by:st
2 Comments
 
LVL 2

Accepted Solution

by:
kswinney earned 50 total points
ID: 1445135
Try this code:

Dim lLineWidth As Long
   
With ActiveDocument.PageSetup
    lLineWidth = .PageWidth - .LeftMargin - .RightMargin
End With
   
lLineWidth = lLineWidth - Selection.ParagraphFormat.LeftIndent - Selection.ParagraphFormat.RightIndent
   
ActiveDocument.Shapes.AddLine 0, 0, lLineWidth, 0, Selection.Range


That should do it.  Cheers!
0
 
LVL 1

Author Comment

by:st
ID: 1445136
That is work! Thanks.
However, MS Word enabled the new line with "move object with text" feature by default.

Would you mind tell me how to disable the "move object with text" feature for the new line?

Thank you for your kind of help.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now