Hi, I'm making a macro that will move whatever text I have selected to the beginning of the sentence, capitalize it, then de-capitalize the original first word of the sentence. The code is below:

Sub MoveToBeginningSentence()
    Application.ScreenUpdating = False
    
    Selection.Cut
    Selection.MoveLeft Unit:=wdSentence, Count:=1, Extend:=wdMove
    Selection.Collapse Direction:=wdCollapseStart
    Selection.Paste
    'Move text to the beginning


    Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
    Selection.Range.Case = wdLowerCase
    'Normalize old word
    
    Selection.MoveLeft Unit:=wdSentence, Count:=1, Extend:=wdMove
    Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
    Selection.Range.Case = wdTitleWord
    'Capitalize new beginning
End Sub
However, if the sentence has a punctuation mark of some kind at the beginning, there will be 2 issues.

Take this sentence as an example: "We haven't seen her today."

If I select today and apply the macro, this will be the new sentence: Today 'We haven't seen her today.'

As you can see, the word Today got pushed outside of the quotation mark. And since the mark is recognized as an entire word by itself, the macro won't select We and make it a lowercase word.

I've come up with a possible solution:
  • Before pasting, have the macro select the first word of the sentence and see if it's either ' or ". If that's the case, move right 1 character, then paste. If not, deselect, go back to the beginning, and paste.
  • After pasting, select the next word, see if it's either ' or ". If that's the case, select the next word to the right and de-capitalize. If not, de-capitalize right away.


The problem is I don't know how to detect specific characters in a string/selection. Is there any way to do that?

And if you have any better solution for those issue, I'm all ears.