View Single Post
 
Old 01-03-2024, 09:32 AM
hss001 hss001 is offline Windows 10 Office 2021
Novice
 
Join Date: Dec 2023
Posts: 20
hss001 is on a distinguished road
Default

Hi gmayor.

I tried this and it works fine if the sentence is not the last cell. But if the sentence is the last cell it returns weird characters (I think they are end of table chars).

Thanks


Quote:
Originally Posted by gmayor View Post
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
Reply With Quote