Solved

VBA: Make Horizontal Line on MS WORD document

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA/SQL - Connect to SQL server and pull data 4 111
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 47
Recommendation vb6 to vb.net or others 14 150
Child Form in front 4 47
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

809 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