View Single Post
 
Old 02-01-2018, 07:50 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
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

It is straightforward and relies on the use of a range

Code:
Sub Pluriel()
'Declare the variables used
Dim oRng As Range
Dim lngCase As Long
    'set a range to the word the cursor is in
    Set oRng = Selection.Words(1)
    'establish the case of the word
    lngCase = oRng.Case
    'if the word ends in a space or non-breaking space remove that space from the range
    oRng.MoveEndWhile Chr(32) & Chr(160), wdBackward
    'Collapse the range to its end
    oRng.Collapse 0
    
    If lngCase = 1 Then 'its upper case
        oRng.Text = "S" ' write S to the range
    Else 'its not upper case
        oRng.Text = "s" 'write s to the range
    End If
lbl_Exit: 'set a marker - not essential
    Set oRng = Nothing 'clear the range
    Exit Sub 'and finish
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