Start Word with macro

  • Hi DragonL,


    To run a macro in Word automatically on open, then you are looking to change the Normal.DOT and add in the Autoexec macro.


    As an example ...


    To create a macro that will automatically open the last file that you edited when you start Word, follow these steps:


    On the Tools menu, point to Macro, and then click Macros.


    In the Macros dialog box, type AutoExec in the Macro Name box, and then click Create.


    In the Microsoft Visual Basic (macro editing) window, type the following macro:


    Sub Autoexec()
    RecentFiles(1).Open
    End Sub

    On the File menu, click Close and Return to Microsoft Word.


    Quit Microsoft Word.


    NOTE: If you are prompted with the following message, click Yes.


    Changes have been made that affect the global template, Normal.dot. Do you want to save those changes?

    When you restart Microsoft Word, Word will automatically open the last file you edited (changed).



    Hope this helps



    Cheers

    [SIZE=6]S[/SIZE][SIZE=6]t[/SIZE][SIZE=6]u[/SIZE] :drum:

  • Maybe I am doing something wrong, but I cant get it to work. I created the AutoExec Macro in normal.dot and put in a simple yes/no box for testing when Word opens. It doesnt ask me to save changes to the global template normal.dot though. After I restart Word the macro did not run. What went wrong?

  • So hopefully, if you went into the VBE screen you had something like


    Sub Autoexec()
    '
    ' Autoexec Macro
    ' Macro created 14/06/2004 by Stu
    '


    MsgBox "Hello"




    End Sub





    Then when I closed Word, re-opened, the message box appeared



    Perhaps, post back what you have if this doesn't trigger anything



    Cheers

    [SIZE=6]S[/SIZE][SIZE=6]t[/SIZE][SIZE=6]u[/SIZE] :drum:

  • I tried this:


    Sub Autoexec()
    msgbox "test"
    End Sub


    After this I restarted Word and no message box appeared. I think it might be a problem with creating the macro. Are all new Macros supposed to start in the NewMacros Module? That is where Autoexec() goes when I create it. I also tried creating an AutoExec Module but that didn't help either. The macro works fine when I run it but does not come up when starting Word. Hope this narrows it down. :P


    -DragonL

  • Use these events instead:


    Code
    Private Sub Document_New()
     msgbox "Hey, dude"
    End Sub
    
    
    Private Sub Document_Open()
     msgbox "Hey, dude"
    End Sub


    Now, whether you open any document, or create a new document, it'll run.
    But it will NOT run when you just open Word...


    What do you want to do when you open Word?

  • I could not get it to work. Where do you put the strings of code at? Any module? There is a strange problem with one of the computers at where I work. Everytime Word is opened on that computer, a "ì" character is attached to the bottom of every new document and opened document. It isnt easy to get rid of either, it doesnt delete or clear like a normal character. So I created a macro to do some steps to hide the ì and I want it to run everytime Word is opened. It isnt a problem with the macro, it's a problem with it actually starting up when Word does.


    -DragonL

  • LOL!


    You're just fixing a symptom instead of correcting a problem. To correct the problem: Find and rename the normal.dot file on that computer. (I don't advise using code to clean something that shouldn't be there in the first place.)


    :)


    Troubleshooting Word: http://www.theofficeexperts.com/word.htm (for your future reference, and tells you how to delete or rename normal.dot).


    Anyway, instructions to add that code, should you ever need it for some better purpose:


    Open Word.
    Hit Alt+F11 to open the VB Editor.
    Double-click ThisDocument under "Normal" on the left-hand side.
    Paste the code into the code window at right.
    Save and close the VB Editor.

  • Thanks a lot :) That should help me fix normal.dot. By the way, I like that site; there's lots of handy information there. <stupid question> Is that your site? </stupid question> Do you know of anyway to keep the default document (Document1) from opening up when Word is started up? Oh and if you know how to keep the default workbook from coming up with Excel that would be helpful too.


    Thanks for the help. :)


    -DragonL

  • Thanks again :)
    I just remembered that I was playing around with that the other day and found the switches for that in file types in folder options, but there were a few extra switches there that I'm curious about that weren't on microsoft's support page. /f and /dde. What are these for? dde = Dynamic Data Encryption?


    -DragonL

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!