View Single Post
 
Old 12-16-2023, 12:28 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
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 issue relates to how many sentences there are in the table cell and which sentence the selection occurs in. If the selection is in the last sentence or only sentence in the cell, the whole cell is selected. You can test for this and make the necessary adjustment e.g.


Code:
Dim orng As Object
    Set orng = oWordApp.Selection.Range
    If orng.Information(12) Then
        If orng.Sentences(1) = orng.Cells(1).Range.Sentences.Last Then
            Set orng = orng.Cells(1).Range.Sentences.Last
            orng.End = orng.End - 1 'omit the table cell end character
            orng.Select
         Else
            orng.Sentences(1).Select
        End If
    Else
        orng.Sentences(1).Select
    End If
__________________
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