Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-06-2016, 09:40 PM
NevilleT NevilleT is offline Check for a horizontal line Windows 7 64bit Check for a horizontal line Office 2003
Novice
Check for a horizontal line
 
Join Date: Mar 2015
Posts: 29
NevilleT is on a distinguished road
Default Check for a horizontal line

I have an application that inserts a horizontal line in a Word document. I want to check if a horizontal line has already been inserted in the prior line. In other words, I don't want to insert a second horizontal line if there is already one there.

I am using this code to check the prior line. It tells me there is an inline shape, but not if it is a line. Can anyone help me establish if the inline shape is a horizontal line.

Selection.MoveUp

If Selection.InlineShapes.Count = 0 Then
Selection.MoveDown



' Create the line
Selection.InlineShapes.AddHorizontalLineStandard

' Line size and alignment
Set shpLine = ThisDocument.InlineShapes(ThisDocument.InlineShape s.Count)
shpLine.HorizontalLineFormat.PercentWidth = 80
shpLine.HorizontalLineFormat.Alignment = wdHorizontalLineAlignRight

End If
Reply With Quote
  #2  
Old 01-06-2016, 10:04 PM
gmayor's Avatar
gmayor gmayor is offline Check for a horizontal line Windows 10 Check for a horizontal line Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following will warn you if there is a hoirizontal line in the current or previous paragraph
Code:
Option Explicit

Sub InsertHorizontalLine()
Dim shpLine As InlineShape
Dim oShape As InlineShape
Dim orng As Range
    Set orng = Selection.Range
    ' Check the previous paragraph
    If Not orng.Start = ActiveDocument.Range.Start Then
        If orng.Paragraphs(1).Previous.Range.InlineShapes.Count > 0 Then
            Set oShape = orng.Paragraphs(1).Previous.Range.InlineShapes(1)
            If oShape.Type = 6 Then
                MsgBox "Line exists in the previous paragraph?"
                GoTo lbl_Exit
            End If
        End If
    End If
    ' Check the current paragraph
    If orng.Paragraphs(1).Range.InlineShapes.Count > 0 Then
        Set oShape = orng.Paragraphs(1).Range.InlineShapes(1)
        If oShape.Type = 6 Then
            MsgBox "Line exists in the current paragraph?"
            GoTo lbl_Exit
        End If
    End If
    ' Create the line
    Set shpLine = orng.InlineShapes.AddHorizontalLineStandard
    ' Line size and alignment
    shpLine.HorizontalLineFormat.PercentWidth = 80
    shpLine.HorizontalLineFormat.Alignment = wdHorizontalLineAlignRight
lbl_Exit:
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 01-06-2016, 11:50 PM
NevilleT NevilleT is offline Check for a horizontal line Windows 7 64bit Check for a horizontal line Office 2003
Novice
Check for a horizontal line
 
Join Date: Mar 2015
Posts: 29
NevilleT is on a distinguished road
Default

Thanks Graham. That looks like it will do the job. I need to do some modifications but the core is great. I have used VBA extensively in Access but have to learn how to do it in Word. Same but different.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
smart art horizontal line sgroves20 Word 0 11-05-2014 08:17 AM
Check for a horizontal line a troubling horizontal line mingming Word 1 09-14-2014 05:16 AM
unable to delete a horizontal line jerryny Word 2 03-31-2013 05:59 PM
Check for a horizontal line How to set month+1 and horizontal line nightkn8 Word 12 03-25-2013 02:06 PM
Check for 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 02:46 PM.


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