none
Issue with Microsoft Word command line switch(es) RRS feed

  • Question

  • Here's my goal: in an automated way, take a columnar report (ascii file) with no page headings and convert it to a .pdf file with page headings (a title, date and time, and page numbers).  So I thought, here's an easy project: I'll use Word's command line interface to load the report file into Word using a template (to provide the formatting I want), and use a macro to save as a .pdf.

    So I  read the instructions at http://office.microsoft.com/en-us/word-help/command-line-switches-for-microsoft-office-word-2007-HP010164010.aspx and then took these steps:

    1) Created a Word macro-enabled template (.dotm) file with some simple formatting (landscape, Courier font, 10 pt, and a header that has the title, etc.) and a macro that loads the report file and saves as a .pdf.  When I created the macro I saved it in "Documents based on <myTemplate>.dotm.

    2) Made sure the ascii file that I want to open exists (this file will always have the same name; it's refreshed periodically by another process).

    3) Wrote a batch file that contains in its entirety the following:

    C:\"Program Files"\"Microsoft Office"\Office12\winword.exe /q /tC:\<mytemplate>.dotm

    where <mytemplate> is the name of my template file.

    When I execute the batch file Word opens (although the /q switch doesn't seem to be suppressing the splash), but then I get the error "The directory name is not valid. (C:\Files\Microsoft.doc)".  I acknowledge the message and I'm sitting in a new Word document that's not based on my template.

    If I move the batch file to another location, e.g., C:\stuff, I get the same message, but referencing "C:\stuff\Files\Microsoft.doc".  So it seems to be appending "Files\Microsoft.doc" to the location of my batch file.  I've also tried using the a standard template file (.dotx), and the \f switch with a regular file (.docx), e.g.,

    C:\"Program Files"\"Microsoft Office"\Office12\winword.exe /q /f C:\MyTest.docx

    and get identical results. 

    I'm running this on a laptop with Windows XP Professional, version 2002, SP3.

    Am I being oblivious to something obvious?  Any thoughts would be much appreciated.  This seems like something that should just work.


    -Geoff
    Friday, March 11, 2011 12:19 AM

Answers

  • Office 12 is Office 2007, so assuming that is OK you should be looking at
     
    "C:\Program Files\Microsoft Office\Office12\winword.exe" /q /f
    "C:\MyTest.docx"
     
    or simply
     
    "C:\MyTest.docx"
     
    though that will give you the splash screen.
    --
     
     
     
     

    Graham Mayor - Word MVP
    www.gmayor.com
    Posted via the Communities Bridge
    http://communitybridge.codeplex.com/
    • Marked as answer by Geoff7512 Friday, March 11, 2011 9:34 PM
    Friday, March 11, 2011 12:03 PM

All replies

  • Office 12 is Office 2007, so assuming that is OK you should be looking at
     
    "C:\Program Files\Microsoft Office\Office12\winword.exe" /q /f
    "C:\MyTest.docx"
     
    or simply
     
    "C:\MyTest.docx"
     
    though that will give you the splash screen.
    --
     
     
     
     

    Graham Mayor - Word MVP
    www.gmayor.com
    Posted via the Communities Bridge
    http://communitybridge.codeplex.com/
    • Marked as answer by Geoff7512 Friday, March 11, 2011 9:34 PM
    Friday, March 11, 2011 12:03 PM
  • Thank you, Graham.  A small change but a big difference in results.

    -Geoff
    Friday, March 11, 2011 9:35 PM