Consulting

Results 1 to 6 of 6

Thread: Put word in bracket when cursor is upon word

  1. #1

    Put word in bracket when cursor is upon word

    Cursor is upon a word of a sentence.
    and
    I have this:
    monotony
    I want this:
    (monotony)

  2. #2
    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
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Contributor
    Joined
    Jul 2020
    Location
    Sun Prairie
    Posts
    123
    Location
    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.

  4. #4

    Yes I should have used Insertion Point.

    I used wrong word. I should have used 'Insertion Point'. Thanks for bringing it to mind.

  5. #5
    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.

  6. #6
    Quote Originally Posted by gmayor View Post
    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.
    Last edited by anilsharaf; 06-30-2021 at 09:53 PM. Reason: forgot someting to tell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •