• Word macro code help please (Word 2K)

    Author
    Topic
    #376520

    Yikes, everyone at this assignment is looking at *me* as the Word expert and I’ve avoided learning any VBA. I want to make a macro that will enclose any selection in parentheses. Sometimes, the selection is a one or two word phrase, and sometimes it is a number in a table cell. I can record a macro to add an opening parenthesis to my selection, and I get the following code, but I’m not certain how to also get a closing parenthesis, without reselecting.

    Selection, moveleft unit:=wdCharacter, Count:=1
    Selection.Typetext Text:=”(“

    Viewing 1 reply thread
    Author
    Replies
    • #616979

      I’m not a VBA expert, but will this work for you?

      Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
      Selection.InsertBefore “(”
      Selection.InsertAfter “)”

      Cheers,

    • #617015

      Once you have the SElection, do not do the move left, instead do something like:

      selection.range.insertbefore “(”
      selection.range.insertafter “)”

      • #617038

        Thanks very much. The range.insertbefore and insertafter make a lot of sense to me, but I couldn’t seem to locate them in any kind of Microsoft help. I’ll be looking for those VBA/macro books you recommend on your website.

        • #617050

          Don’t fret.
          It takes time to learn this stuff.

          Once you read a book and better understand the concepts and big picture, you’ll know better how to use the Help and object broswer.

        • #617341

          It is possible that VBA help wasn’t installed with Office 2000; it might require a custom installation. You will know if you open the VBE (press Alt+F11 inside Word to open the Visual Basic Editor) and type selection.range.insertbefore, then select any part of it and press F1. If the VBA help was installed, you should get a very specific screen, if not, well, I’m not sure what you get… Anyway, type what you know, then select it and press F1, is the best way I know to figure out the mysteries of “what comes next” using the built-in help files.

    Viewing 1 reply thread
    Reply To: Word macro code help please (Word 2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: