PDA

View Full Version : [SOLVED:] Put word in bracket when cursor is upon word



anilsharaf
06-27-2021, 04:28 PM
Cursor is upon a word of a sentence.
and
I have this:
monotony
I want this:
(monotony)

gmayor
06-27-2021, 08:13 PM
This should work

Sub Macro1()
Dim orng As Range
Set orng = Selection.Words(1)
Do While Right(orng, 1) = Chr(32)
orng.End = orng.End - 1
Loop
orng.InsertAfter ")"
orng.InsertBefore "("
Set orng = Nothing
End Sub

Chas Kenyon
06-29-2021, 02:32 PM
Note that Graham's macro works with the insertion point (cursor) in the word. It does not work when just the mouse pointer (cursor) is over the word.

anilsharaf
06-30-2021, 07:30 PM
I used wrong word. I should have used 'Insertion Point'. Thanks for bringing it to mind.

anilsharaf
06-30-2021, 07:33 PM
Thanks. It worked well.
I had lost hope when I saw the notice in the Forum that 'You can not post any thing' 'Simils are on' etc. So I was not checking the Forum post.

anilsharaf
06-30-2021, 09:48 PM
This should work

Sub Macro1()
Dim orng As Range
Set orng = Selection.Words(1)
Do While Right(orng, 1) = Chr(32)
orng.End = orng.End - 1
Loop
orng.InsertAfter ")"
orng.InsertBefore "("
Set orng = Nothing
End Sub

Thanks. It worked well for English Font. But one thing more, What if the word is in font 'Kurti Dev 010': In Hindi 'Full stop' is a letter 'n' and English Capital 'A' is a Full Stop. This macro does not take 'Full stop' in word.
I have this Hindi Word (Kurti Dev 010) with Full stop at last.
jke'kj.kA
I want This:
¼jke'kj.k½A
¼ is an opening bracket and ½ is a closing bracket.