Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Opening a Text File and Template from the Command Line.

# Opening a Text File and Template from the Command Line

by Allen Wyatt
(last updated January 7, 2012)

Dan wants to open a text file (txt extension) with Word, from the command line, using a specific template. Only problem is, he is having some problems doing it. Dan can put together the proper command line, according to Word's Help system, but it still doesn't work.

Actually, this makes sense that it doesn't work. Consider for a moment that templates are used with Word documents, not with text files. Text files are just that: text. Even in Word they are still text. Yes, you can attach a template to a text file opened in Word, but at that point the "attachment" is not complete unless you still save the document in Word format. So, when you use a command line such as the following, it won't work:

"c:\Program Files\Microsoft Office\Office\Winword.exe" "d:\text.txt" /t"MyTemplate.dot"


It is the /t switch that is supposed to tell Word which template to use with the file it opens. The reason is that Word ignores any template specification is because it knows that template files don't go with text files. Instead, Word opens the file with the standard template, Normal.dot. Word also ignores the template switch even if you use /z instead of /t. (The /z switch is the same as /t, except that it opens Word in a slightly different manner than with /t.)

The fact that Normal.dot is used for text files provides one way that you can work around Word's apparent shortcoming in this area. You could, for instance, rename your existing Normal.dot template as something else (such as OldNormal.dot) and then rename the template you want to use as Normal.dot. When you open the text file from the command line, the desired set of styles will be in the new Normal.dot file and attached to the text file.

Another option that is perhaps better is to use a macro to attach the desired template to your text file. Yes, you could create a macro that you manually run after loading the text file, but a better way is to set things up so that it happens automatically. For instance, you might have a macro such as this in your Normal.dot template:

Sub TextTemplate()
With ActiveDocument
.AttachedTemplate = "d:\test files\MyTemplate.dot"
.XMLSchemaReferences.AutomaticValidation = True
.XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
End With
End Sub


While you could run this macro manually to attach the MyTemplate.dot template to your document, you could also use the following from the command line:

"c:\Program Files\Microsoft Office\Office\Winword.exe" "d:\text.txt" /m"TextTempate"


In this case, the text file is opened and the TextTemplate macro is run. This works because Normal.dot (where TextTemplate is stored) is attached to the text file, and then the macro attaches the other template automatically.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (455) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Opening a Text File and Template from the Command Line.

##### Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

##### MORE FROM ALLEN

Creating a Directory in a Macro

One of the things you can do with macros is to work with disk files. As you do so, you may have a need to create a new ...

Discover More

Specifying Superscript Text

Applying different formatting to the text within a cell can seem a bit confusing. This is certainly the case when it comes to ...

Discover More

Understanding Shortcuts

One way of optimizing your user interface is through the use of shortcuts. This tip provides a brief overview of what ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

Cannot Open Multiple Word Documents

What are you to do if you try to open a document and Word automatically closes your previous document? Word is not supposed ...

Discover More

Opening a Document as Read-Only in Windows Explorer

Discover More

Creating a Document Clone

If you need to work with a copy of a document rather than the original document, you can use Word's Open dialog box to ...

Discover More
##### Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is three more than 8?

2012-10-15 13:36:10

lovenish

i want to insert the a particular text and images to a file . what i want is , how i set a particular word for those text and images means whenever i want to insert those text and images , i only type a text and press enter and the whole text and image comes automatically in the word document any time or in any word file

##### This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.