Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Putnam Valley, New York, USA
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word macro code help please (Word 2K)

    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:="("

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word macro code help please (Word 2K)

    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,

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word macro code help please (Word 2K)

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

    selection.range.insertbefore "("
    selection.range.insertafter ")"

  4. #4
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Putnam Valley, New York, USA
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word macro code help please (Word 2K)

    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.

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word macro code help please (Word 2K)

    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.

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Word macro code help please (Word 2K)

    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.

Posting Permissions

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