#1
|
|||
|
|||
Find if the selection is a horizontal line
I want to check the current selection to see if it is a horizontal line. If not, I will insert a horizontal line. I have not found a value I can check. I also wanted to check if it is a table and that part of the code works OK
CheckTable: If Selection.Information(wdWithInTable) Then Selection.MoveDown unit:=wdLine, Count:=1 GoTo CheckTable End If I basically want to do the same thing for a horizontal line. |
#2
|
||||
|
||||
There is no 'horizontal line' object in Word. In Word, horizontal lines can be created as underlines, hyphens and the like, table cell borders, inlineshapes or shapes. Each kind would have to be tested for separately. Then you'd have to decide what kind of horizontal line you want to insert and how to place & size it as required.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
This is the code I am using to set the line.
Selection.ParagraphFormat.LeftIndent = InchesToPoints(1.4) ' Set the value of the indent Selection.InlineShapes.AddHorizontalLineStandard ' Add the line |
#4
|
||||
|
||||
For that, you could try something like:
Code:
Sub Demo() With Selection.Paragraphs(1).Range.Characters(1).Previous.Paragraphs(1).Range If .InlineShapes.Count = 0 Then Selection.ParagraphFormat.LeftIndent = InchesToPoints(1.4) ' Set the value of the indent Selection.InlineShapes.AddHorizontalLineStandard ' Add the line ElseIf .InlineShapes(1).Type <> wdInlineShapeHorizontalLine Then Selection.ParagraphFormat.LeftIndent = InchesToPoints(1.4) ' Set the value of the indent Selection.InlineShapes.AddHorizontalLineStandard ' Add the line End If End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Hi and thanks for the reply. That worked perfectly.
I have used Access VBA for decades but never ventured into Word VBA. Still getting to understand the object model and the commands you never use in Access. Appreciate your help. |
Tags |
horizontal line |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Check for a horizontal line | NevilleT | Word VBA | 2 | 01-06-2016 11:50 PM |
smart art horizontal line | sgroves20 | Word | 0 | 11-05-2014 08:17 AM |
a troubling horizontal line | mingming | Word | 1 | 09-14-2014 05:16 AM |
How to set month+1 and horizontal line | nightkn8 | Word | 12 | 03-25-2013 02:06 PM |
Horizontal sawtooth line | JamesT | Word | 3 | 10-29-2011 05:39 PM |