How to crate a new document from command line using MS Word with a specific file name?

16
2014-04
  • 01es

    Is it possible to create a new MS Word document based on some template from a command line in such a way that it would be stored automatically into the specified file?

    The command below creates a new document based on the specified template. However, this new document needs to be saved interactively from MS Word.

    winword /tc:/tmp/template.dot
    

    What I would like to happen is for a new document to be saved automatically upon creation into the specified file. So, something like the command below where /file would be a flag that points to the required file, would be do the trick.

    winword /tc:/tmp/template.dotx /file c:/tmp/new-document.docx
    

    I could not find any command line flags for MS Word to achieve such behaviour. Perhaps this is not available or I've missed it.

    Thank you.

  • Answers
  • Timothy

    If you just need a new, empty Word document, you could use the following:

    echo. 2>"New Document.docx"

    All this does is creating an empty file; empty as you echo nothing into it. The file opens properly with Word 2013, haven't tested with other versions. The reason that it opens in Word, is simply because of the file extension.

    Note that instead of just the file name, you can use a whole path and name here.

    Edit: Alternative that is quite simpler:

    copy NUL "New Document.docx"

    Simply copy the contents of NUL into the new file. In DOS, NUL is in fact a file/device that always contains nothing.


  • Related Question

    MS Word document randomly changes document filename from .doc to .tmp
  • anD666

    I am experiencing problems when opening some word documents.

    The filename will randomly automatically change to the temp file that is created whilst editing the document.

    MS Word is not crashing and it doesnt happen for everyone on our network that I know of.

    Can anyone shed some light on why it would do this?

    Thanks


  • Related Answers
  • DMA57361

    The .tmp files are created for various reasons when editing a Word doc (see here http://support.microsoft.com/kb/211632 for more info), I believe they are harmless, a good thing in fact (they ensure safety when saving, for example) and should disappear when you stop using the original file - leaving the .doc intact (or possibly updated if you edit and save).

    If Word is asking you to save files as .tmp when you've been editing them a while it might be a known issue (especially since you mention networked files). See the following support page for advise on checking if this is the case (and fixing it, if it is) - http://support.microsoft.com/kb/912257/en-us