How to run a procedure in a Word Document as soon as it is newly created RRS feed

  • Question

  • I have a VS2010 program that creates a Word 2007 file.

    My file is customised to give me a new Tab with Buttons in that do specific things via VBA in the program when those Buttons are pressed.

    This all works fine, however, I now want to add some functionality whereas as soon as the new Word document is created, it edits a Task in Outlook via the VBA code (I have this code ready to apply, this is not the problem, I need to make it execute, that is the problem !).

    I have edited the 2 "This Document" Procedures and you can see my Normal.Dot file in the attached Screenshot.

    When I run my VB.Net program that creates a brand new Word 2007 document, the VBA code in the template does NOT stop on either of the message boxes, it just continues and opens the Word document exactly as before, my code is below, what am I doing wrong ?!?

        'Open or Create Word document for Editing
        myNewsLetter = myFolder + myLeague + "News" + mySession + ".doc"
        If File.Exists(myNewsLetter) Then
            'do nothing
            myTemplate = myTempFolder + "NL Skeleton.doc"
            File.Copy(myTemplate, myNewsLetter)
        End If
        'Open Word Newsletter, or switch to it if it's already open
        Dim myFileOpen As Boolean
        myFileOpen = IsFileOpen(myNewsLetter)
        If myFileOpen = False Then
            MSDoc = MSWord.Documents.Open(myNewsLetter)
        End If
        MSWord.WindowState = Word.WdWindowState.wdWindowStateNormal
        MSWord.Visible = True

    • Edited by vodkasoda Friday, March 8, 2013 7:33 PM More detail
    Friday, March 8, 2013 7:31 PM

All replies

  • See responses to your question at

    If you are going to post the same question to multiple forums, have the courtesy to include links to those forums so other users can check for a response before going to the effort of developing one.

    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org

    Saturday, March 9, 2013 6:52 AM
  • I would have put the link in when I got an answer or helpful responses, Doug,  but when I went to bed there were no responses ... in any case, thank you for your help.
    Saturday, March 9, 2013 9:40 AM