Solved

VBA: Make Horizontal Line on MS WORD document

Posted on 1998-11-16
2
1,816 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

911 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

24 Experts available now in Live!

Get 1:1 Help Now