View Single Post
 
Old Yesterday, 10:14 AM
RobiNew RobiNew is offline Windows 11 Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 229
RobiNew is on a distinguished road
Default Macro to delete ending period at the end of a single paragraph

Hi! I use this macro to delete an ending period at the end of a single paragraph.
Is there a way to delete the period without having to re-insert the paragraph mark?
Thanks!
Code:
Sub DeleteEndingFullStop()
    Dim para As Paragraph
    Dim txt As String
    Set para = Selection.Paragraphs(1)
    txt = para.Range.Text
    ' Check if paragraph ends with a period before the paragraph mark
    ' check the character before vbCr (ASCII 13)
    If Len(txt) > 1 Then
        If Mid$(txt, Len(txt) - 1, 1) = "." Then
            ' Remove the ending period
            para.Range.Text = Left$(txt, Len(txt) - 2) & vbCr
        End If
    End If
End Sub

Last edited by macropod; Yesterday at 01:50 PM. Reason: Correct code tag usage
Reply With Quote