View Single Post
 
Old 01-07-2022, 05:18 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
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

It is easy enough to determine whether the selection is in a table and if it is to select one of the cells in that table and set the range to that cell's content. e.g.
Code:
Sub Macro1()

Dim WrdTemplate As Template
Dim objBB As BuildingBlock
Dim WrdRng As Range

    Set WrdRng = Selection.Range
    If WrdRng.Information(wdWithInTable) = True Then    'the selection is in a table
        Set WrdRng = Selection.Cells(1).Range    'the first cell in the selection
        WrdRng.End = WrdRng.End - 1    'omit the end of cell character from the range
    End If
    Set WrdTemplate = Application.Templates("filepath")
    Set objBB = WrdTemplate.BuildingBlockTypes(wdTypeCustom1).Categories("Legislation").BuildingBlocks("END")
    objBB.Insert WrdRng
    
    Set objBB = Nothing
    Set WrdRng = Nothing
    Set WrdTemplate = Nothing
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