Solved

VBA: Make Horizontal Line on MS WORD document

Posted on 1998-11-16
2
1,979 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

717 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