none
AutoNew at Word Startup RRS feed

  • Question

  • We need to alter some document properties for the default new document that is created when Word starts up. This is based on some regional location information we glean from the computer. I'd rather not go with different versions of the Normal template, to ease management issues.

    In Word 2007, we used the AutoNew method in the Normal.dot to affect the changes, but in Word 2010, AutoNew does not fire for the default new document, only for documents created after Word opens. I've also tried using application events, Application_DocumentOpen, but with the same results.

    Any help would be appreciated.

    Friday, March 7, 2014 2:55 PM

Answers

  • Hi cwaldmann,

    Here is a workaround for Word 2010, please try to add the code below to Normal.dot and let me know whether it works.

    Sub AutoNew()
        DoSthToNewDoc
    End Sub
    
    Sub AutoExec()
        WaitForActiveDocument
    End Sub
    
    Sub WaitForActiveDocument()
        If Application.Documents.Count = 0 Then
            Application.OnTime (Now() + TimeValue("00:00:01")), "WaitForActiveDocument"
        Else
            DoSthIfNewDoc
        End If
    End Sub
    
    
    Sub DoSthIfNewDoc()
        Dim ext As String
        
        ext = Right(Application.ActiveDocument.Name, 4)
        
        'new document do not have extension
        If ext <> "docx" Then
            DoSthToNewDoc
        End If
    End Sub
    
    Sub DoSthToNewDoc()
        MsgBox "Do Sth to New Document"
    End Sub
    


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by cwaldmann Wednesday, March 12, 2014 2:36 PM
    Wednesday, March 12, 2014 12:05 PM
    Moderator

All replies

  • Hi,

    According to your description, the AutoNew method didn’t fire when you start the Word application. As far as I test, the method doesn't execure nithor in Word 2007 or Word 2010 when the application is started.

    I suggest you using AutoExec if you want to do some customization when you start the Word application.
    You can get more detail about auto macros from article below:

    Auto Macros

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 10, 2014 3:17 AM
    Moderator
  • I would be fine using AutoExec, but there is no active document at the time of AutoExec, unless I'm missing a way to access the default document
    Monday, March 10, 2014 2:26 PM
  • Hi cwaldmann,

    Here is a workaround for Word 2010, please try to add the code below to Normal.dot and let me know whether it works.

    Sub AutoNew()
        DoSthToNewDoc
    End Sub
    
    Sub AutoExec()
        WaitForActiveDocument
    End Sub
    
    Sub WaitForActiveDocument()
        If Application.Documents.Count = 0 Then
            Application.OnTime (Now() + TimeValue("00:00:01")), "WaitForActiveDocument"
        Else
            DoSthIfNewDoc
        End If
    End Sub
    
    
    Sub DoSthIfNewDoc()
        Dim ext As String
        
        ext = Right(Application.ActiveDocument.Name, 4)
        
        'new document do not have extension
        If ext <> "docx" Then
            DoSthToNewDoc
        End If
    End Sub
    
    Sub DoSthToNewDoc()
        MsgBox "Do Sth to New Document"
    End Sub
    


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by cwaldmann Wednesday, March 12, 2014 2:36 PM
    Wednesday, March 12, 2014 12:05 PM
    Moderator
  • Thanks. Great workaround.

    I made a couple of alterations. The time lag of 1 second seems to run into an issue when you open Word by opening an existing document. Runs into the "Cannot execute code in break mode" error.

    http://www.pcreview.co.uk/forums/ontime-code-error-cant-execute-code-break-mode-t2746053.html

    So, I switched it to 2 seconds. I think it will be fine for our purposes.

    Also, on the extension, I changed it to check for the 6 right characters and if the first 4 of those = "umen" or "ment" (docUMENt1, docuMENT11), then execute the AutoNew. That should give it plenty of leeway.

    Wednesday, March 12, 2014 2:36 PM