none
Word 2010 AutoExec Macro wtih ActiveDocument.Name

    Question

  • I have the following AutoExec macro in a Word 2010 Startup Template.  When word starts, it looks to see if the active document is Document1. If so, it attaches a custom styles template, so our firm styles are available in every new document. Works perfect in Word 2007. any ideas why it does not work or how to fix this in 2010?

    Sub AutoExec()
        On Error Resume Next
        If ActiveDocument.NAME = "Document1" Then
        With ActiveDocument
            .UpdateStylesOnOpen = True
            .AttachedTemplate = "C:\Word2010UI\Workgroup\MUStyles.dotx"
            .XMLSchemaReferences.AutomaticValidation = True
            .XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
        End With
        With ActiveDocument
            .UpdateStylesOnOpen = False
            .AttachedTemplate = "C:\Word2010UI\Workgroup\MUStyles.dotx"
            .XMLSchemaReferences.AutomaticValidation = True
            .XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
        End With
        End If
    End Sub

    • Moved by Shanks Zen Friday, March 23, 2012 2:49 AM VBA issue (From:Visual Basic General)
    Wednesday, March 21, 2012 10:10 PM

Answers

  • As usual, as soon as I post I figure it out..

    Sub AutoExec()
        Application.OnTime When:=Now + TimeValue("00:00:01"), NAME:="AddDoc1Styles"
    End Sub

    Works perfect.

    Thursday, March 22, 2012 12:02 AM

All replies

  • You may have better luck getting an answer in the Visual Basic Applications forum.

    http://social.msdn.microsoft.com/Forums/en/isvvba/threads

    This is for VB.Net.

    Wednesday, March 21, 2012 11:36 PM
  • Thanks... thought that's where I was, but apparently got routed to the wrong forum somehow. 
    Wednesday, March 21, 2012 11:48 PM
  • I have the following AutoExec macro in a Word 2010 Startup Template.  When word starts, it looks to see if the active document is Document1. If so, it attaches a custom styles template, so our firm styles are available in every new document. Works perfect in Word 2007. any ideas why it does not work or how to fix this in 2010?

    Sub AutoExec()
        On Error Resume Next
        If ActiveDocument.NAME = "Document1" Then
        With ActiveDocument
            .UpdateStylesOnOpen = True
            .AttachedTemplate = "C:\Word2010UI\Workgroup\MUStyles.dotx"
            .XMLSchemaReferences.AutomaticValidation = True
            .XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
        End With
        With ActiveDocument
            .UpdateStylesOnOpen = False
            .AttachedTemplate = "C:\Word2010UI\Workgroup\MUStyles.dotx"
            .XMLSchemaReferences.AutomaticValidation = True
            .XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
        End With
        End If
    End Sub

    Wednesday, March 21, 2012 11:50 PM
  • As usual, as soon as I post I figure it out..

    Sub AutoExec()
        Application.OnTime When:=Now + TimeValue("00:00:01"), NAME:="AddDoc1Styles"
    End Sub

    Works perfect.

    Thursday, March 22, 2012 12:02 AM
  • Thanks for your sharing and have a nice day! :)

    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us

    Friday, March 23, 2012 8:36 AM
    Moderator