GrumpyCrouton
GrumpyCrouton

Reputation: 8621

Microsoft Word 2013 macro to replace selected text is deselecting text afterwards

I've created a very simple macro that is supposed to just add a prefix and suffix to selected text.

This works, but there is a slight problem; when the macro is triggered, the prefix and suffix are added BUT the text is also deselected. I would like for the macro to add the prefix and suffix, yet still keep the text that was selected selected.

Here is my macro, I've tried searching around for a fix for this but have not been able to find anything;

Sub Quote_Text()
    With Selection.Range
        .Text = Chr(34) & .Text & Chr(34)
    End With
End Sub

Upvotes: 0

Views: 1049

Answers (1)

Tim Williams
Tim Williams

Reputation: 166585

Sub Quote_Text()
    With Selection.Range
        .Text = Chr(34) & .Text & Chr(34)
        .Select   '<<<<<
    End With
End Sub

Upvotes: 2

Related Questions