View Single Post
 
Old 01-06-2016, 10:04 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,138
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 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