• File New Macro in Word 2002 (VBA Word 2002)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » File New Macro in Word 2002 (VBA Word 2002)

    Author
    Topic
    #392381

    I have a Word 2002 macro called FileNew in a module called FileNew in my Startup template. It runs fine when I select New from the File menu, or when I press Ctrl+N. But the macro doesn’t run at all when I use the toolbar to create a new blank document, or when Word first starts up with a blank document. Is there another way to create a FileNew macro that will run in all four instances?

    Viewing 1 reply thread
    Author
    Replies
    • #704123

      The action of the “New” button on the toolbar is to open a new document based on Normal.dot, not to run the action of File | New… If you select Tools | Customize…, and activate the Commands tab, you will find both “New…” and ‘New’ in the File category. Remove the “New” button from the toolbar, and drag “New…” to its place.

      I don’t know offhand how to make Word run the FileNew macro only if it isn’t started with a document. Putting FileNew in an AutoExec macro may have undesired side effects; I don’t know what your FileNew macro does.

    • #704181

      First, it might be better not to name your module FileNew. If you ever add a MAIN procedure to that module, there could be a conflict with the procedure named FileNew. But this is just an aside…on to the main event.

      The “new blank document” toolbar button runs FileNewDefault. Create a new procedure such as:

      Sub FileNewDefault()
      FileNew ‘call your macro
      End Sub

      With respect to Word starting up, you would need to put an AutoNew macro in Normal.dot, I think, but I’m not sure that will do what you want. What does your FileNew macro do?

      • #704901

        My FileNew macro is quite simple really. I have 11 styles that we want to make ‘standard’ for all new documents. We already have a Startup template that performs many other functions, so we thought we could just add a FileNew macro to copy the styles into each new document. I have since decided FileNew is not the way to go, and have instead added an AutoExec macro to the Startup template which copies the desired styles from our standard styles template into the Normal.dot.

        The only problem with this is that it doesn’t handle the first ‘Document 1’ that is created when Word starts up. I have found that the order of execution when Word starts is to create a new blank document based on the Normal.dot, then load the global (Startup) template, then run AutoExec macros in the global (Startup) template. We don’t want to push down a standard Normal.dot, we would rather just add to it from the Startup template. So, it seems one way or the other, that first document will not be affected. I have done what I consider to be a very clumsy fix, and that is, in the Startup template’s AutoExec macro, I have it close Document 1, then copy the styles to Normal.dot, then create a new blank document (which ends up being Document 2). It works, but I don’t particularly like users always starting Word on a Document 2 screen rather than Document 1.

        Any other suggestions? Isn’t there a way to run a macro prior to Word creating Document 1? Possibly a switch or something at the Word startup?

        • #704902

          Instead of closing Document1, why don’t you just transfer the 11 styles into it? Since the blank document already exists when the AutoExec is run, that should not be problematic.

          • #704915

            Funny you should suggest that! Just after I posted my last reply I thought of that and was just coding it and testing it when I got your email! It works like a charm, thank you.

            So, the AutoExec macro handles it so that the first document has the styles copied into it, and it copies the styles into Normal.dot so that all future blank documents have the styles.

            The only loop hole then is if during that Word session the user modifies the styles and updates them to their Normal.dot, which would mean any new documents for that session would be using alternate styles (the AutoExec macro would handle that for the next Word session). I’m thinking, while not glamorous, I might still use a File New macro to handle this loop hole. A File, New macro could ensure that even if they did that, new documents created during that Word session would use the appropriate styles (by copying the styles to each new word document), and then when the next Word session is opened, the AutoExec macro would overwrite the Normal.dot. I would rather not run the code to copy the styles in a File, New macro, mainly because it is just extra overhead every time a new document is created, especially if the user hasn’t modified the Normal.dot. But, when I thought of doing something like comparing the styles in the new document with the ones in our ‘standard’ styles template each time a new blank document is created, well, that’s just as much overhead as the File, New approach!

            Any suggestions there? I have the File, New working right now, but I’m just trying to find the ‘best’ way to handle this!

            • #704917

              If you distrust your users this much you have a problem anyway – they can also modify the styles in existing documents…

            • #704987

              While neither here nor there wrt the question posted, it’s not that we distrust the users. We are in a municipal government environment, and the powers that be have asked that each ‘new’ document start off with the recommended styles. From there, if necessary, of course the users can modify the styles to suit the individual document’s needs. If they routinely require a unique set of styles for a particular purpose, that is also accommodated through a process whereby they are provided with instructions on how they can develop their own template, or the IT department will even develop it for them. But, the object of the game, per what has been asked of us, it to ensure that all blank ‘new’ documents, not created from a template, always _start_ off with the standard recommended styles.

            • #704990

              Thanks for the explanation.

              If you can’t enforce a standard Normal.dot, or copy the styles into Normal.dot when Word is started, I’d say copy the styles into each new document. I haven’t tested it, but testing the styles won’t be much more efficient, if at all, then just copying them.

              There is one other problem: if the user right clicks in Windows Explorer, and selects New | Word Document, a copy is made of Winword8.doc in C:WindowsShellNew. The user can then double click this document, and you have no way to distinguish it from other existing documents. I assume that you don’t want to copy the styles into existing documents, so …

    Viewing 1 reply thread
    Reply To: File New Macro in Word 2002 (VBA Word 2002)

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

    Your information: