none
macros don't execute on document open using /t switch on command line RRS feed

  • Question

  • I'm trying to invoke a Word merge document from within a program using a /t switch as follows:

    "%MSWORDDIR%\winword.exe" /q /t"%NAVDIR%\Templates\lc_generic_form_template.dot"

    When I execute this command the macros fail to execute.  If I open the template directly from Word the macros execute and if I leave off the /t switch from the command line the macros execute, but this places the user in the template rather than a document derived from the template.  I have tried events Document_Open() and Document_New() as well as macros AutoOpen() and Auto_New(), all to no avail when using /t.

    I'm working in Word 2003 on XP Pro and have users with W2003 and W2007.

    Thanks in advance if anyone has any suggestions regarding this.

    Thursday, December 2, 2010 1:39 AM

Answers

  • Hi Quartus

    Yes, the /t switch does not allow "Auto" macros to execute. You need the /z switch. But please note that this is only available for Word 2007 and later.

    Is there any particular reason you're "shelling" to create a new document, rather than using the interop/automation?


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Quartus Thursday, December 2, 2010 4:56 PM
    Thursday, December 2, 2010 7:44 AM
    Moderator

All replies

  • Hi Quartus

    Yes, the /t switch does not allow "Auto" macros to execute. You need the /z switch. But please note that this is only available for Word 2007 and later.

    Is there any particular reason you're "shelling" to create a new document, rather than using the interop/automation?


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Quartus Thursday, December 2, 2010 4:56 PM
    Thursday, December 2, 2010 7:44 AM
    Moderator
  • Hi Cindy --

     

    Thanks for the answer.  That certainly explains it.

     

    I've been a developer (primarily unix) for 25 years, but this is my first foray into the Word world and was unaware of the interop/automation feature you suggest.  I do not generally develop using Microsoft products.  Are you able to point me to a tutorial so that I can determine if this is feasible from my development platform?

    Thursday, December 2, 2010 5:04 PM
  • Hi Quartus

    What's your development platform? (I know next to nothing about Unix, so we're even!)

    "Interop" or "automation" is basically communicating via the exposed COM OLE interface of the Office application. Usually, this is not something you want to do from "server-side" and it's even a bit touchy done "remotely" (from another machine)... It's more something you'd do from an independent program running on the user's machine, such as VB6, .NET WinForm, Delphi...


    Cindy Meister, VSTO/Word MVP
    Thursday, December 2, 2010 6:43 PM
    Moderator
  • The development platform is a little know OO 4GL called Vision from Unify.  It allows deployment on either unix or windows platforms.  The user deployment is on PCs running Windows XP so it is akin to programs such as Delphi.  Vision does have a class for communication with ActiveX objects.
    Thursday, December 2, 2010 7:03 PM
  • The development platform is a little know OO 4GL called Vision from Unify.  It allows deployment on either unix or windows platforms.  The user deployment is on PCs running Windows XP so it is akin to programs such as Delphi.  Vision does have a class for communication with ActiveX objects.


    Hi Quartus

    Then it would almost certainly be possible, but I'm not sure what kind of documentation to point you at...

    If I want to initiate a new instance of an Office application, in (for example) VB-speak I'd do:

    Dim wdApp as Word.Application = New Word.Application()

    and in C# it would be:

    Word.Application wdApp = new Word.Application();

    For this to work, I'd have had to set a reference to the COM Type Library, which in its turn needs to have been registered under Windows (HKLC - if you look you'll see Word.Application listed).

    Through wdApp I can access the rest of the object library. To open a document, for example:

    Dim wdDoc as Word.Document = wdApp.Documents.Open([parameters here])

    Does that sound familiar at all or make any sense in your context?


    Cindy Meister, VSTO/Word MVP
    Thursday, December 2, 2010 7:18 PM
    Moderator
  • Cindy --

    Thanks.  Yes it does make sense.  Let me explore this and I'll revert if I have any specific questions.

    Thursday, December 2, 2010 7:26 PM