Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    May 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing word commands (XP SP1)

    In Word 95 and 97 I could alter the built in Word commands (macros) eg change FileOpen to ALWAYS show a certain directory regardless of what the user did previously. Is this option still available in Word XP? if so what is the procedure? I can only create a macro in the 'newmacros' project, not in MAIN.

  2. #2
    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: Changing word commands (XP SP1)

    I don't have XP, but I have spent about 15 minutes in the VB Editor and it seems to be the largely same as Word 2000.

    If you want to add your new macro to the Normal.dot template, you should be able to add a new module for your code using Insert|Module. (It helps to have the Project Explorer window open so you can be sure that you are inserting into the correct template.) Unlike macros converted from Word 95, where each macro get its own module containing a Main procedure, you can simply group your macros together in whatever manner seems to make the most sense. For example, the Module name might be FirmCustom and the procedure name might be Sub FileOpen().

    If you want to add your macro to a global template, you usually have to open the template directly before you can access the modules. Otherwise, they are locked.

    Does this help?

  3. #3
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts

    Re: Changing word commands (XP SP1)

    Yes, you can replace any of the Word commands, I think. You can create macros in any module you want, but you can only record them in NewMacros.

    IMO, the MAIN module is an anachronism in VBA and generally shows converted WordBasic code and/or someone who may not have really learned VBA yet. Doesn't necessarily hurt anything, but usually isn't any more helpful than "NewMacros."

    If you name a macro FileOpen, it will replace that command in any document where the macro is active.

    Take a look at Intercepting Events Like Save and Print and at other files on the MVP VBA FAQ page to get a head-start on this.
    Charles Kyle Kenyon
    Madison, Wisconsin

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

    Re: Changing word commands (XP SP1)

    You can create a macro by using alt F11 to open the VBIDE, then right click in the Projects window to insert a module.

    In the module's Properties window, name the module something like modCodeForApp1.

    Then in the module itself, use code such as:

    Public Sub SomeMacroName()
    ' Put code here
    end sub

    Private Sub SomeCodeLocalToThisModule(arg list)
    'Put code here
    end sub

    In general, I prefer to have a separate module for each macro, but that's a personal choice.

    For example, in my Normal template, I have two modules. One contains all th Auto* macros and related code. The other is a macro that cannot be in the global templates because te global templates are not loaded in time when Word starts up and the macro is called by the Auto macros.

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

    Re: Changing word commands (XP SP1)

    I have a bunch of code that works equally well/poorly in both VB and VBA.

    Main is necessary if you wish to develop code that "might" be used by both VB and VBA, as VB requires that the startup object be either Main or a Userform.

  6. #6
    New Lounger
    Join Date
    May 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing word commands (XP SP1)

    Thanks for the replies guys... I have found the solution (but not totally sure what is going on....)
    I kept testing the macro gradually adding msgbox-s to see what was going on . (It was only 3 or 4 lines to start with!) changefileopendir - op-default-wddocumentspath etc and dialog.show with "*.doc" etc.
    Nothing was happening - the curfolder kept showing the last place the user went looking. - when I went checking for my default folder locations I noticed that my 'server' (on a peer-peer network - Win2Kpro) , on its own explorer window shows the workgroup folders in their physical location. I was trying to use those locations as the defaults in this PC's Word|Options.
    However when I went delving on this PC's explorer window I saw that the workgroup folders could also be seen hanging off the server's root directory with network icons next to them. Sort of logical folders?
    When I set Word's Options to these folders (the logical ones) my macro worked just dandy.
    All this networking stuff with Win2K is newbie-land for me - a steep learning curve - but we got there in the end.
    I appreciate having this lounge to visit - I'm sure I'll be back to keep up with the play - thanks v.much
    and - if anyone is a Win2K expert out there maybe they could let me know if there are any other tricks/tips on how to deal with them! - (I promise to buy a Win2K book real soon!)
    Neil

  7. #7
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts

    Re: Changing word commands (XP SP1)

    Well, that explains a lot to me, since I haven't explored VB more than to glance through a book or two. Thank you.
    Charles Kyle Kenyon
    Madison, Wisconsin

Posting Permissions

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