Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-24-2016, 11:07 PM
NevilleT NevilleT is offline Find if the selection is a horizontal line Windows 7 64bit Find if the selection is a horizontal line Office 2003
Novice
Find if the selection is a horizontal line
 
Join Date: Mar 2015
Posts: 29
NevilleT is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 06-25-2016, 03:37 AM
macropod's Avatar
macropod macropod is offline Find if the selection is a horizontal line Windows 7 64bit Find if the selection is a horizontal line Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 06-25-2016, 05:31 AM
NevilleT NevilleT is offline Find if the selection is a horizontal line Windows 7 64bit Find if the selection is a horizontal line Office 2003
Novice
Find if the selection is a horizontal line
 
Join Date: Mar 2015
Posts: 29
NevilleT is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 06-25-2016, 07:17 PM
macropod's Avatar
macropod macropod is offline Find if the selection is a horizontal line Windows 7 64bit Find if the selection is a horizontal line Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 06-26-2016, 12:17 AM
NevilleT NevilleT is offline Find if the selection is a horizontal line Windows 7 64bit Find if the selection is a horizontal line Office 2003
Novice
Find if the selection is a horizontal line
 
Join Date: Mar 2015
Posts: 29
NevilleT is on a distinguished road
Default

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.
Reply With Quote
Reply

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
Find if the selection is a horizontal line a troubling horizontal line mingming Word 1 09-14-2014 05:16 AM
Find if the selection is a horizontal line How to set month+1 and horizontal line nightkn8 Word 12 03-25-2013 02:06 PM
Find if the selection is a horizontal line Horizontal sawtooth line JamesT Word 3 10-29-2011 05:39 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:01 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft