Excel for Microsoft 365 Word for Microsoft 365 Outlook for Microsoft 365 PowerPoint for Microsoft 365 Access for Microsoft 365 Excel 2021 Word 2021 Outlook 2021 PowerPoint 2021 Access 2021 Excel 2019 Word 2019 Outlook 2019 PowerPoint 2019 Access 2019 Excel 2016 Word 2016 Outlook 2016 PowerPoint 2016 Access 2016 Excel 2013 Word 2013 Outlook 2013 PowerPoint 2013 Access 2013 Excel 2010 Word 2010 Outlook 2010 PowerPoint 2010 Access 2010 Excel 2007 Word 2007 Outlook 2007 PowerPoint 2007 Access 2007 More…Less
When you launch a Microsoft Office product, the startup process runs in a standard way. Microsoft Word, for example, displays the Word splash screen and loads the Normal template. But suppose you want Word to start without its splash screen and then load a template other than the Normal template. Or, you want to customize the process even more by loading an add-in or running a macro upon startup. You can add options like this by using subcommands called command-line switches to an Office app’s startup command.
If you want to use the customization just one time, you can type the command and switch in the Run dialog box (Start menu) in Microsoft Windows. If you want to use a particular switch many times or every time that you start the app, you can create a desktop shortcut that starts the program by using the same switch and parameters. This article describes how to do both. It also includes a table that lists all of the switches and parameters that are available in the desktop Office apps.
Using a command-line switch doesn’t mean you have to type the whole startup command at the command prompt. You can start the Office app as usual, by clicking the program icon on the desktop, or by clicking the program name on the Start menu. All startup methods essentially do the same thing: they run the app’s .exe file, even if you don’t actually type the command or even see it.
A command-line switch is a modifier that is added to the .exe file. A startup file with a switch looks like this.
outlook.exe /nopreview
In this example, a command-line switch has been added to the .exe file for Microsoft Outlook. The switch consists of a forward slash and a word or abbreviation that indicates the switch’s action. This switch tells Outlook to launch without showing the Reading Pane.
A switch is sometimes followed by one or more specific instructions called parameters, which give the program further information about how to run the .exe command. For example, the following command tells Outlook to load a specific profile name upon startup.
outlook exe /profile profilename
Switch names cannot be abbreviated and are not case-sensitive. However, their parameters are sometimes case-sensitive.
Here are the names of the startup commands for the Office products Word, Excel, PowerPoint, PowerPoint viewer, Outlook, and Access.
Word |
winword.exe |
Excel |
excel.exe |
PowerPoint |
powerpnt.exe |
PowerPoint Viewer |
pptview.exe |
Outlook |
outlook.exe |
Access |
msaccess.exe |
When you use one of the Office startup commands, you must supply the full path to the product’s .exe file. Verify the location of this file on your computer. This table shows the locations of the .exe files if you accepted the default folder locations during installation.
In Office 2007 |
Windows 32-bit: C:Program Files (x86)Microsoft OfficeOffice12 Windows 64-bit: C:Program FilesMicrosoft OfficeOffice12 |
In Office 2010 |
Windows 32-bit: C:Program Files (x86)Microsoft OfficeOffice14 Windows 64-bit: C:Program FilesMicrosoft OfficeOffice14 |
In Office 2013 |
Windows 32-bit: C:Program Files (x86)Microsoft OfficeOffice15 Windows 64-bit: C:Program FilesMicrosoft OfficeOffice15 |
In Office 2016 |
Windows 32-bit: C:Program Files (x86)Microsoft OfficeOffice16 Windows 64-bit: C:Program FilesMicrosoft OfficeOffice16 |
In Office 365 |
Windows 32-bit: C:Program Files (x86)Microsoft OfficerootOffice16 Windows 64-bit: C:Program FilesMicrosoft OfficerootOffice16 |
-
In Windows 10, click the Search or Cortana icon in the taskbar, type Run, and then click Command Prompt in the results.
In Windows 8, press the Windows key, type Run, and then press Enter.
In Windows 7, click Start, point to All Programs, click Accessories, and then click Run.
-
In the Run dialog box, type a quotation mark, enter the full path for the app’s .exe file, and then type another quotation mark. Alternatively, click Browse to locate and select the file. In this case, the quotation marks are supplied automatically.
-
After the closing quotation mark, type a space, and then type the switch. For example, you might type:
"c:program filesmicrosoft officeoffice15outlook.exe" /nopreview
The next time you start the app, it opens as usual. To make your customized startup available for repeated uses, see the next section.
Note the following about using command-line switches:
-
You can use only one switch at a time. Starting an Office app with multiple switches is not supported.
-
If the parameter is a path to a location on your computer, or a file name with spaces in it, enclose it in double quotation marks—for example, /t «Monthly Report.dotx».
-
Switches and parameters are not case-sensitive. For example, /RO functions the same as /ro.
-
Include one blank space before each switch and one before each parameter.
-
Right-click the Windows desktop, point to New, and then click Shortcut on the shortcut menu.
-
In the Create Shortcut Wizard, in the Type the location of the item box, type a double quotation mark («), enter the full path for the app’s .exe file (including the file name), and then type another double quotation mark. (Alternatively, click Browse to locate and select the file. In this case, the quotation marks are added automatically.)
-
Following the closing quotation mark, type a space, and then type the switch and any parameters. If the parameter is a path to a location on your computer, and the path contains a space, it also must be enclosed in quotation marks. For example:
"c:program filesmicrosoft officeoffice15excel.exe" /r "c:My Folderbook1.xlsx"
-
Click Next.
-
In the Type a name for this shortcut box, type a name for the shortcut, and then click Finish.
The wizard creates the shortcut and places it on the desktop.
Whenever you want to use the shortcut to start the app, double-click it.
To add the desktop shortcut to the Windows Start menu, right-click the shortcut, and then click Pin to Start menu on the shortcut menu.
List of command-line switches for Office products
Each Office product has a different set of command-line switches.
Note: These lists don’t include all switches added since Office 2007. If you use command-line switches and want information about newer switches that are available, please respond Yes or No to the «Was this information helpful» question at the end of this topic. Then, in the box that appears, tell us which Office product and version you’re interested in.
Switch and parameter |
Description |
---|---|
/safe |
Starts Word in Safe Mode. |
/q |
Starts Word without displaying the Word splash screen. |
/ttemplatename |
Starts Word with a new document based on a template other than the Normal template. Example To start Word with a document based on a template called Myfax.dotx, stored on the C drive, type the following at the command prompt: /tc:Myfax.dotx Note: Do not include a space between the switch and the name of the template file. Security Note: Because templates can store macro viruses, be careful about opening them or creating files based on new templates. Take the following precautions: run up-to-date antivirus software on your computer, set your macro security level to high, clear the Trust all installed add-ins and templates check box, use digital signatures, and maintain a list of trusted sources. |
/t filename |
Starts Word and opens an existing file. Example To start Word and open the template file Myfax.dotx, stored on the C drive, type the following at the command prompt: /t c:Myfax.dotx Example To start Word and open multiple files, such as MyFile.docx and MyFile2.docx, each stored on the C drive, type the following at the command prompt: /t c:MyFile.docx c:MyFile2.docx |
/f filename |
Starts Word with a new document based on an existing file. Example To start Word and create a new document based on file MyFile.docx, stored on the desktop, type the following at the command prompt: /f «c:Documents and SettingsAll UsersDesktopMyFile.docx» |
/h http://filename |
Starts Word and opens a read-only copy of a document that is stored on a Microsoft Windows SharePoint Services site. The site must be on a computer that is running Word 2007 or later or Windows SharePoint Services 2.0 or later. Example To start Word and open a copy of file MyFile.docx, stored in a document library at the URL http://MySite/Documents, type the following at the command prompt: /h http://MySite/Documents/MyFile.docx Note: If the document is checked out to you, the /h switch has no effect. Word opens the file so that you can edit it. |
/pxslt |
Starts Word and opens an existing XML document based on the specified Extensible Stylesheet Language Transformation (XSLT). Example To start Word and apply the XSLT MyTransform, stored on the C drive, to the XML file Data.xml, also stored on the C drive, type the following at the command prompt: /pc:MyTransform.xsl c:Data.xml |
/a |
Starts Word and prevents add-ins and global templates (including the Normal template) from being loaded automatically. The /a switch also locks the setting files. |
/ladd-in |
Starts Word and then loads a specific Word add-in. Example To start Word and then load the add-in Sales.dll, stored on the C drive, type the following at the command prompt: /lc:Sales.dll Note: Do not include a space between the switch and the add-in name. Security Note: Use caution when running executable files or code in macros or applications. Executable files or code can be used to carry out actions that might compromise the security of your computer and data. |
/m |
Starts Word without running any AutoExec macros. |
/mmacroname |
Starts Word and then runs a specific macro. The /m switch also prevents Word from running any AutoExec macros. Example To start Word and then run the macro Salelead, type the following at the command prompt: /mSalelead Note: Do not include a space between the switch and the macro name. Because macros can contain viruses, be careful about running them. Take the following precautions: run up-to-date antivirus software on your computer; set your macro security level to high; clear the Trust all installed add-ins and templates check box; use digital signatures; maintain a list of trusted publishers. |
/n |
Starts a new instance of Word with no document open. Documents opened in each instance of Word will not appear as choices in the Switch Windows list of other instances. |
/w |
Starts a new instance of Word with a blank document. Documents opened in each instance of Word will not appear as choices in the Switch Windows list of the other instances. |
/r |
Re-registers Word in the Windows registry. This switch starts Word, runs Office Setup, updates the Windows registry, and then closes. |
/x |
Starts Word from the operating system shell so that Word responds to only one Dynamic Data Exchange (DDE) request (for example, to print a document programmatically). |
/ztemplatename |
Visibly behaves exactly like the /t switch. However, you can use the /z switch with Word to generate both a Startup and a New event, whereas the /t switch generates only a Startup event. |
Switch and parameter |
Description |
---|---|
workbook path | file name This parameter does not require a switch. |
Starts Excel and opens the specified file. Example excel.exe «c:My Folderbook1.xlsx» or excel.exe http://MySite/Book1.xlsx |
/r |
Opens a specific workbook as read-only. Example excel.exe /r «c:My Folderbook1.xlsx» or excel.exe /r http://MySite/Book1.xlsx |
/t |
Starts Excel and opens the specified file as a template. Example excel.exe /t «c:My Folderbook_name.xlsx». or excel.exe /t http://MySite/book_name.xlsx |
/n |
Like /t, starts Excel and opens the specified file as a template. Example excel.exe /n «c:My Folderbook_name.xlsx». or excel.exe /n http://MySite/book_name.xlsx |
/e or /embed |
Prevents the Excel startup screen from appearing and a new blank workbook from opening. Example excel.exe /e |
/p |
Specifies a folder as the active working folder (for example, the folder that is pointed to in the Save As dialog box). Example excel.exe /p «c:My Folder» |
/s or /safemode |
Forces Excel to bypass all files that are stored in startup directories, such as the default XLStart folder located in the directory where Excel or Microsoft Office is installed. Example excel.exe /s |
/m |
Creates a new workbook that contains a single XLM macro sheet. Example excel.exe /m |
/a |
Starts Excel and loads the Automation add-in that is specified by the progID of the add-in. Example excel.exe /a MyProgId.MyProgID2.1 |
/x |
Starts a new instance (a separate process) of Excel. Example excel.exe /x «c:My Folderbook1.xlsx» or excel.exe /x http://MySite/Book1.xlsx |
Here are the command-line switches that are available for PowerPoint.
Switch or parameter |
Action |
---|---|
/B |
Starts PowerPoint with a new blank presentation. Example: «c:program filesmicrosoft officeoffice12POWERPNT.exe» /B |
/C |
Starts PowerPoint with the specified file open and also starts Microsoft Windows NetMeeting conferencing. Example: «c:program filesmicrosoft officeoffice12POWERPNT.exe» /C NetMeetingPresentation.pptx Note: If you use this switch without specifying a file, PowerPoint starts with no presentation open and NetMeeting conferencing is not started. |
/EMBEDDING |
Starts PowerPoint without displaying the Office PowerPoint 2007 program window. Developers use this switch when testing add-ins. Example: «c:program filesmicrosoft officeoffice12POWERPNT.exe» /EMBEDDING |
/M MACRO |
Runs a macro in a specified presentation. Example: «c:program filesmicrosoft officeoffice12POWERPNT.exe» /M myfile.pptm «MyMacro» «MyMacro» is a macro in the file myfile.pptm. |
/N |
Starts PowerPoint and creates a new presentation. Example: «c:program filesmicrosoft officeoffice12POWERPNT.exe» /N «Pathtemplatename.potx» This example specifies the name of the template that the new presentation is based on: templatename.potx. If a template name is not supplied, PowerPoint starts a new presentation based on the blank template (in effect, the same as using the /N switch without a template name). |
/O |
Starts PowerPoint and specifies a list of files to open. Example: «c:program filesmicrosoft officeoffice12POWERPNT.exe» /O File name1.pptx, File name2.pptx |
/P |
Prints the presentation to the default printer by using default settings. When you use the /P switch, PowerPoint displays the Print dialog box before printing. After you choose options and click OK, the dialog box closes, and PowerPoint prints the file and then closes. If you don’t want to see PowerPoint at all, use the /PT (Print To) switch instead. Example: «c:program filesmicrosoft officeoffice12POWERPNT.exe» /P «MyFile.pptx» |
/PT |
Prints the presentation to the specified printer by using the default settings. If you don’t want to see PowerPoint at all, use the /PT (Print To) switch. Example: «c:program filesmicrosoft officeoffice12POWERPNT.exe» /PT «PrinterName» «» «» «MyFile.pptx» PrinterName is the name of the printer that appears in the Name box under Printer in the Print dialog box. The empty quotation marks are necessary; the quotation marks around PrinterName and the path to the PPTX file are needed only if there are spaces in either of the names, but it is always a good idea to use them. |
/PWO |
Prints the specified file, but show the Print dialog box. When you use the /P switch, PowerPoint displays the Print dialog box before printing. After you choose options and click OK, the dialog box closes, and PowerPoint prints the file and then closes. If you don’t want to see PowerPoint at all, use the /PT (Print To) switch instead. Example: «c:program filesmicrosoft officeoffice12POWERPNT.exe» /PWO «MyFile.pptx» |
/RESTORE |
Restores PowerPoint to the way it was before the program closed abnormally. When PowerPoint restarts, it will attempt to recover and restore some aspects of the state of the program and presentations before it closed. Example: «c:program filesmicrosoft officeoffice12POWERPNT.exe» /RESTORE |
/S |
Opens the specified presentation file as a slide show. Example: «c:program filesmicrosoft officeoffice12POWERPNT.exe» /S «Presentation1.pptx» |
Here are the command-line switches that are available for PowerPoint Viewer.
Switch or parameter |
Action |
---|---|
/D |
Shows the Open dialog box when the presentation ends. Example: «c:program filesmicrosoft officeoffice12PPTVIEW.exe» /D |
/L |
Reads a playlist of PowerPoint presentations contained within a text file. Example: «c:program filesmicrosoft officeoffice12PPTVIEW.exe» /L «Your_Play_List.txt « Note: The playlist file is a list of presentation file names (preceded by the path as needed). It is not possible to add additional command-line switches to the individual presentations within the playlist. |
/N# |
Opens the presentation at a specified slide number, instead of slide 1. Example: «c:program filesmicrosoft officeoffice12PPTVIEW.exe» /N5 «Presentation.pptx» This example opens Presentation.pptx at slide 5. |
/S |
Starts the viewer without showing the splash screen. Example: «c:program filesmicrosoft officeoffice12PPTVIEW.exe» /S |
/P |
Sends the presentation to a printer, and print the file. Example: «c:program filesmicrosoft officeoffice12PPTVIEW.exe» /P «Presentation.pptx» This example prints the Presentation.pptx file. |
Switch |
Description |
---|---|
/a |
Creates an item with the specified file as an attachment. Example:
If no item type is specified, IPM.Note is assumed. Cannot be used with message classes that are not based on Outlook. |
/altvba otmfilename |
Opens the VBA program specified in otmfilename, instead of %appdata%microsoftoutlookvbaproject.otm. |
/c messageclass |
Creates a new item of the specified message class (Outlook forms or any other valid MAPI form). Examples:
|
/checkclient |
Prompts for the default manager of e-mail, news, and contacts. |
/cleanautocompletecache |
Removes all names and e-mail addresses from the Auto-Complete list. (Outlook 2013, 2016 only) |
/cleancategories |
Deletes any custom category names that you have created. Restores categories to the default names. |
/cleanclientrules |
Starts Outlook and deletes client-based rules. |
/cleanconvongoingactions |
Deletes the Conversations Actions Table (CAT). CAT entries for a conversation thread usually expire 30 days after no activity. The command-line switch clears all conversation tagging, ignore, and moving rules immediately stopping any additional actions. (Outlook 2013, 2016 only) |
/cleandmrecords |
Deletes the logging records saved when a manager or a delegate declines a meeting. |
/cleanfinders |
Resets all Search Folders in the Microsoft Exchange mailbox for only the first profile opened. |
/cleanfromaddresses |
Removes all manually added From entries from the profile. |
/cleanmailtipcache |
Removes all MailTips from the cache. (Outlook 2013, 2016 only) |
/cleanreminders |
Clears and regenerates reminders. |
/cleanroamedprefs |
All previous roamed preferences are deleted and copied again from the local settings on the computer where this switch is used. This includes the roaming settings for reminders, free/busy grid, working hours, calendar publishing, and RSS rules. |
/cleanrules |
Starts Outlook and deletes client-based and server-based rules.
|
/cleanserverrules |
Starts Outlook and deletes server-based rules. |
/cleansharing |
Removes all RSS, Internet Calendar, and SharePoint subscriptions from Account Settings, but leaves all the previously downloaded content on your computer. This is useful if you cannot delete one of these subscriptions within Outlook 2013. |
/cleansniff |
Overrides the programmatic lockout that determines which of your computers (when you run Outlook at the same time) processes meeting items. The lockout process helps prevent duplicate reminder messages. This switch clears the lockout on the computer it is used. This enables Outlook to process meeting items. |
/cleansubscriptions |
Deletes the subscription messages and properties for subscription features. |
/cleanweather |
Removes city locations added to the Weather Bar. |
/cleanviews |
Restores default views. All custom views you created are lost. |
/embedding |
Used without command-line parameters for standard OLE co-create. |
/f msgfilename |
Opens the specified message file (.msg) or Microsoft Office saved search (.oss). |
/finder |
Opens the Advanced Find dialog box. |
/hol holfilename |
Opens the specified .hol file. |
/ical icsfilename |
Opens the specified .ics file. |
/importNK2 |
Imports the contents of an .nk2 file which contains the nickname list used by both the automatic name checking and Auto-Complete features. |
/importprf prffilename |
Starts Outlook and opens/imports the defined MAPI profile (*.prf). If Outlook is already open, queues the profile to be imported on the next clean start. |
/launchtraininghelp assetid |
Opens a Help window with the Help topic specified in assetid displayed. |
/m emailname |
Provides a way for the user to add an e-mail name to the item. Only works together with the /c command-line parameter. Examples:
|
/noextensions |
Both native and managed Component Object Model (COM) add-ins are turned off. |
/nopreview |
Starts Outlook with the Reading Pane off. |
/p msgfilename |
Prints the specified message (.msg). |
/profile profilename |
Loads the specified profile. If your profile name contains a space, enclose the profile name in quotation marks (» «). |
/profiles |
Opens the Choose Profile dialog box regardless of the Options setting on the Tools menu. |
/promptimportprf |
Same as /importprf except a prompt appears and the user can cancel the import. |
/recycle |
Starts Outlook by using an existing Outlook window, if one exists. Used in combination with /explorer or /folder. |
/remigratecategories |
Starts Outlook and starts the following commands on the default mailbox:
Note: This is the same command as Upgrade to Color Categories in each Outlook mailbox properties dialog box. |
/resetfolders |
Restores missing folders at the default delivery location. |
/resetfoldernames |
Resets default folder names (such as Inbox or Sent Items) to default names in the current Office user interface language. For example, if you first connect to your mailbox in Outlook by using a Russian user interface, the Russian default folder names cannot be renamed. To change the default folder names to another language, such as Japanese or English, you can use this switch to reset the default folder names after you change the user interface language or install a different language version of Outlook. |
/resetformregions |
Empties the form regions cache and reloads the form region definitions from the Windows registry. |
/resetnavpane |
Clears and regenerates the Folder Pane for the current profile. |
/resetquicksteps |
Restores the default Quick Steps. All user-created Quick Steps are deleted. |
/resetsearchcriteria |
Resets all Instant Search criteria so the default set of criteria is shown in each module. |
/resetsharedfolders |
Removes all shared folders from the Folder Pane. |
/resettodobar |
Clears and regenerates the To-Do Bar task list for the current profile. |
/restore |
Attempts to open the same profile and folders that were open prior to an abnormal Outlook shutdown. (Outlook 2013, 2016 only) |
/rpcdiag |
Opens Outlook and displays the remote procedure call (RPC) connection status dialog box. |
/safe |
Starts Outlook without the Reading Pane or toolbar customizations. Both native and managed Component Object Model (COM) add-ins are turned off. |
/safe:1 |
Starts Outlook with the Reading Pane off. |
/safe:3 |
Both native and managed Component Object Model (COM) add-ins are turned off. |
/select foldername |
Starts Outlook and opens the specified folder in a new window. For example, to open Outlook and display the default calendar, use: «c:program filesmicrosoft officeoffice15outlook.exe» /select outlook:calendar. |
/share feed://URL/filename /share stssync://URL /share web://URL/filename |
Specifies a sharing URL to connect to Outlook. For example, use stssync://URL to connect a SharePoint list to Outlook. |
/sniff |
Starts Outlook, forces a detection of new meeting requests in the Inbox, and then adds them to the calendar. |
/t oftfilename |
Opens the specified .oft file. |
/v vcffilename |
Opens the specified .vcf file. |
/vcal vcsfilename |
Opens the specified .vcs file. |
Switch |
Parameter |
Description |
---|---|---|
None |
database |
Opens the specified database or Microsoft Access project. You can include a path, if necessary. If the path contains spaces, enclose it in quotation marks. |
/excl |
None |
Opens the specified Access database for exclusive access. To open the database for shared use in a multiuser environment, omit this switch. Applies to Access databases only. |
/ |
None |
Opens the specified Access database or Access project for read-only use. |
/runtime |
None |
Specifies that Access will start with runtime version options. |
/profile |
user profile |
Starts Access by using the options in the specified user profile instead of the standard Windows Registry settings created when you installed Access. This replaces the /ini switch used in versions of Access prior to Access 95 to specify an initialization file. |
/compact |
target database or target Access project |
Compacts and repairs the Access database, or compacts the Access project that was specified before the /compact switch, and then closes Access. If you omit a target file name following the /compact switch, the file is compacted to the original name and folder. To compact to a different name, specify a target file. If you include a path that contains spaces, enclose the path in quotation marks. If you specify a file name in the target database or target Access project parameter but you don’t include a path, the target file is created in the default database folder that is specified in Access. You can change this setting in the Access Options dialog box. In an Access project, this option compacts the Access project (.adp) file but not the Microsoft SQL Server database. |
/x |
macro |
Opens the Access database that was specified before the /x switch, and then runs the specified macro. Another way to run a macro when you open a database is to create a macro named AutoExec. Macros can contain viruses, so you must be careful about running them. Take the following precautions: run up-to-date antivirus software on your computer; use the Trust Center to disable all macros except those that are digitally signed; maintain a list of trusted sources of macros. |
/ |
None |
Specifies that what follows on the command line is the value that will be returned by the Command function. This option must be the last switch on the command line. You can use a semicolon (;) as an alternative to /cmd. Use this switch to specify a command-line argument that can be used in Visual Basic for Applications (VBA) code. |
Need more help?
Want more options?
Explore subscription benefits, browse training courses, learn how to secure your device, and more.
Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.
MSWord-CLI
A Command Line Interface for Microsoft Word
Table of Contents
- Summary
- Installation
- Installing the latest development code
- Making the
msw
command available on your PATH
- Basic Usage
- Chaining
- Plugins
- Dependencies
- License
Summary
MSWord-CLI allows you to control Microsoft Word from the command line and/or automate
it from batch or PowerShell scripts. Among other things, you may create, open, print,
export, save, and close Word documents. Note that MSWord-CLI does not actually edit the
content of any documents. That is beyond the scope of this project.
Warning
This is Pre-Alpha software which is in active development. The various subcommands, options,
and arguments are subject to change without notice and may not be sufficiently tested.
All development has been done on Windows 7 with MS Office 2013. Bug reports are welcome on any
system, although the reporter may need to do much of the work on other systems and/or versions.
Installation
Installing the latest development code
If you would like to use the bleeding edge, you can install directly from the the Github Repo.
However, be aware that this code is not guaranteed to be stable or even run. It is recommended
that stable releases be installed instead. Proceed at your own risk.
From the command line execute the following commands as an Administrator:
> git clone https://github.com/waylan/msword-cli.git > cd msword-cli > python setup.py install
These instructions assume that Git for Windows, Python and Setuptools are already installed
on your system.
Making the msw
command available on your PATH
If you are using Python version 3.4 and you enabled the «Add Python.exe to Path” feature
during installation (off by default), you can skip this section.
Generaly, when running Python, or python scripts from the command line you would need to inlcude the
full path to the script. However, with a little configuration, Windows will find your scripts
without needing to include the full path to the script. You need to tell Windows where the Python
executable (python.exe
) and your scripts (msw.exe
) can be found by inlcuding those directories
in the PATH
environment variable. Therefore, assuming you are using Python version 2.7, add the
following to the PATH
environment variable (with no spaces):
C:Python27;C:Python27Scripts
If you are using a differant version of Python, or if you have installed Python in a non-standard
location, you will need to adjust those paths accordingly. See the Python Guide for more information.
If you are using the Python Launcher (py.exe
), you will not need to add the path to python.exe
to
the PATH
environment variable, but you will still need to add the Scripts
directory, which is where
msw.exe
gets installed.
Basic Usage
To open an existing document:
> msw open mydocument.docx
To print the active (focused) document:
To view a list of all open documents:
> msw docs Open Documents: * [1] mydocument.docx [2] otherdoc.docx
Notice that the asterisk (‘*
‘) indicates that the document at index 1 (mydocument.docx
) is the
currently active document. To change the focus to otherdoc.docx
(at index 2):
> msw activate 2 > msw docs Open Documents: [1] mydocument.docx * [2] otherdoc.docx
Unless otherwise specified all subcommands work on the active document.
For a complete list of commands and options, run msw --help
from the command line. For help
with a specific subcommand, run msw <subcommand> --help
.
Chaining
Subcommands can be chained together. For example, to open a document, print two copies of
pages 2, 3, 4, and 6 of that document, and then close the document, the following single
command is all that is needed:
> msw open somedoc.docx print --count 2 --pages "2-4, 6" close
Note that if any options are specified for a subcommand, those options must be specified after
the relevant subcommand and before the next subcommand in the chain. For instance, in the above
example, somedoc.docx
is an argument of the open
subcommand, --count 2 --pages "2-4, 6"
are options for the print
subcommand and the close
subcommand has no options or arguments
defined.
Without command chaining, three separate commands would need to be issued:
> msw open somedoc.docx > msw print --count 2 --pages "2-4, 6" > msw close
Either method will accomplish the same end result. However, chaining should run a little faster
as the utility only needs to be loaded once for all commands rather than for each command.
Chaining also allows you to run different variations of the same command when that command’s
options are mutually exclusive. For example, the export
subcommand can only accept either
the --pdf
or the --xps
flag. If you want to export to both formats, you can chain two
export
subcommands together :
> msw export --pdf . export --xps .
Note that the dot (‘.
‘) in the above example specifies the current working directory as the
export path. All of the common command line paradigms should work out-of-the-box.
Plugins
MSWord-CLI includes support for third-party plugins. A plugin can add additional subcommands
which can be included in a chain. For example, one might desire to have the ability to import
some data to fill a form (perhaps content controls). While it would be unrealistic to try to
include such a script with MSWord-CLI that could meet everyone’s needs, there is no reason
why an individual user could not develop a special purpose script to meet her specific needs.
While the script could be written as a standalone script, it would also be convenient to be
able to include the call within a chain. That way, the document could be opened, the data imported,
and then the document could be printed and closed — all from a single command.
All commands need to be defined as Click commands. Create a new python file named msw_import.py
and define your command:
import click @click.command('import') def imprt(): ''' Import data. ''' click.echo('Data is being imported...')
Note that while the command is labeled ‘import’ (which will be used from the command line), the
function is named imprt
so as not to clash with Python’s import
statement. Currently, the
new command only prints a mesage to the console and exits. Before developing the new command’s
functionality, tell MSWord-CLI about the new subcommand and verify that it can be called.
To do that, create a second python file named setup.py
and include a setup script:
from setuptools import setup setup( name='MSWImportPlugin', version="1", description="Import plugin for MSWord_CLI", py_modules=['msw_import'], entry_points=""" [msw.plugin] import=msw_import:imprt """ )
The key is in the entry_points
. An entry point was added to the msw.plugin
group named ‘import’
which points to the imprt
function at its path (msw_import:imprt
). Additional commands could
be defined from the same Python module. Simply add an additional line to the entry_points
for
each one.
Finally, for MSWord-CLI to find the new plugin, it needs to be installed.
> python setup.py install
The above command will do the trick. However, as the plugin isn’t finished yet, is would be helpful
to use a special development mode which sets up the path to run the plugin from the source file
rather than Python’s site-packages
directory. That way, any changes made to the file will
immediately take effect with no need to reinstall the plugin.
> python setup.py develop
Now that the plugin is installed, test the script:
You should find the import
subcommand listed among the default subcommands in the help messge.
To ensure that the new subcommand works, try running it:
> msw import
Data is being imported...
As the message was printed to the console, the new import
subcommand is being called. Now
the functionally of the import
subcommand can be fleshed out, which is left as an exercise
for the reader.
Dependencies
MSWord-CLI is built on Python and requires that Python version 2.7 or greater be installed
on the system. In addition to the python packages listed below, you must also have a working
copy of Microsoft Word installed on your system.
Python Packages:
- PyWin32
- Click (version 3)
- Setuptools
License
MSWord-CLI is licensed under the BSD License as defined in LICENSE.txt
.
It is possible to open a word document from the command line using this:
rundll32 url.dll,FileProtocolHandler path.to.word.document.doc
Unfortunately, that document needs an external data source, so the path of that data source has to be set manually once it is opened.
Is there a more convenient way to provide an additional parameter to point to the data source?
Deduplicator
44.3k7 gold badges65 silver badges115 bronze badges
asked Oct 11, 2012 at 9:26
You can open a word document using
winword.exe <filepath>
To use winword in command prompt you need to set your path variable like this
set path=%path%;C:Program FilesMicrosoft OfficeOffice14
answered Feb 19, 2013 at 13:35
In the cmd instance I opened the document but just typing in the document name in
«whatever it’s called.docx»
answered Aug 17, 2016 at 19:30
If you use PowerShell, you can type «ii FileName«. For example, «ii *.docx» will open all the .docx files in the folder. It works for all types of files, not just Word documents.
answered Feb 21, 2018 at 20:45
SarahSarah
1,77617 silver badges17 bronze badges
Like most apps, you can launch Word from the Command Prompt, but Word also supports several optional switches for controlling the startup process.
Whether you type the command at the prompt, use it to create a shortcut, insert it as part of a batch script, launching Word with additional parameters lets you do things like start Word in Safe Mode for troubleshooting or start with a specific template.
Before we can open Word using the Command Prompt, we need to figure out which directory the winword.exe file is located. You can do this manually, or you can just have the Command Prompt find it for you. To do this, go ahead and open the Command Prompt by opening the start menu and typing “cmd” and selecting the “Command Prompt” application.
When you open the Command Prompt, you’ll be in the top tier directory—your user account folder. We need to dig deeper by going into the Program Files directory. Do so by entering the following command and then pressing Enter:
cd”program files (x86)”
You’ll now be in the Program Files directory. The next step is to locate the directory where the winword.exe file is located. Do so by typing the following command and pressing “Enter.”
dir winword.exe /s
Once you enter this command, the Command Prompt will locate the directory for you.
Now that you know the directory where the winword.exe file is located, you can use the cd command to open the file path. In this example, you would need to enter the following command:
cd Microsoft OfficerootOffice16
Now you should be in the directory where winword.exe is located.
Now, if you want to open Microsoft Word the same way as if you were opening it via its icon, all you must do is type winword and then press “Enter,” and Word will open its usual way.
However, the whole point of using the command is that you can use the different switches and parameters it offers.
Common Word Command Line Switches and Parameters
Borrowed from the official Microsoft Office support site, here is a list of some possible ways to open Word, along with its respective command.
Switch and Parameter | Description |
/safe | Starts Word in Safe Mode. This launches Word without any additional add-ins, templates, and other customizations. It’s helpful when troubleshooting problems in Word.
You can also launch Word in Safe Mode by holding down the Ctrl key while launching Word from the Start menu, creating a shortcut with this parameter makes it that much easier. |
/q | Starts Word without displaying the Word Splash screen. |
/ttemplatename | Starts Word with a new document based on a template other than the Normal template.
Example: Assume we wanted to open a document stored on the C drive called example.docx, we’d type the following command: /tc:example.docx Note: Do not put a space between the switch and the name of the file. |
/t filename | Starts Word and opens an existing file.
Example: To start Word and open the existing file example.docx, stored on the C drive, enter the following: /t c:example.docx To open multiple files, example.docx and example2.docx, located in the C drive at once, enter the following: /t c:example.docx c:example2.docx |
/f filename | Starts Word with a new document based on an existing file.
Example: To start Word and create a new document based on file example.docx, stored on the desktop, enter the following: /f “c:Documents and SettingsAll UsersDesktopexample.docx |
/h http://filename | Starts Word and opens a read-only copy of a document that is stored on a Microsoft Windows SharePoint Services site. The site must be on a computer that is running Word 2007 or later or Windows SharePoint Services 2.0 or later.
Example: To start Word and open a copy of a file example.docx, stored in a document library at the URL http://MySite/Documents, enter the following: /h http://MySite/Documents/example.docx Note: If the document is checked out to you, the /h switch has no effect. Word opens the files so that you can edit it. |
/pxslt | Starts Word and opens an existing XML document based on the specified XSLT.
Example: To start and apply the XSLT MyTransform, stored on the C drive, enter the following: /pc:MyTransform.xsl c:Data.sml |
/a | Starts Word and prevents add-ins and global templates (including the Normal template) from being loaded automatically. The /a switch also locks the settings files. |
/ladd-in | Starts Word and then loads a specific Word add-in.
Example: To start Word and load the add-in Sales.dll, stored on the C drive, enter the following: /ic:Sales.dll Note: Do not include a space between the switch and the add-in name. |
/m | Starts Word without running any AutoExec macros. |
/mmacroname | Starts Word and the runs a specific macro. The m/ switch also prevents word from running any AutoExec macros.
Example: To start Word and then run the macro Salelead, enter the following: /mSalelead Note: Do not include a space between the switch and the macro name. |
/n | Starts a new instance of Word with no document open. Documents opened in each instance of Word will not appear as choices in the Switch Windows list of other instances. |
/w | Starts a new instance of Word with a blank document. Documents opened in each instance of Word will not appear as choices in the Switch Windows list of other instances. |
/r | Re-register Word in the Windows registry. This switch starts Word, runs Office Setup, updates the Windows registry, and the closes. |
/x | Starts Word from the operating system shell so that Word responds to only one DDE request (for example, to print a document programmatically). |
/ztemplatename | Visibly behaves exactly like the /t switch. However, you can use the /z switch with Word to generate both a Startup and a New event, whereas the /t switch generates only a Startup event. |
That’s all there is to it! Now you should be able to open Word in any specific way you choose by simply following these commands.
RELATED: How to Run Command Prompt Commands from a Windows Shortcut
READ NEXT
- › How to Make Columns in Microsoft Word
- › How to Find Your IP Address From CMD (Command Prompt)
- › How (and Why) to Start Microsoft PowerPoint from the Command Prompt
- › How to Turn Off Dark Mode in Microsoft Word
- › How to Put Borders Around Images in Microsoft Word
- › How to Link or Embed a PowerPoint Slide in a Word Document
- › How to Insert an Image Inside of Text in Microsoft Word
- › Save Hundreds on Elegoo’s New PHECDA Laser Engraver Through Kickstarter
How-To Geek is where you turn when you want experts to explain technology. Since we launched in 2006, our articles have been read billions of times. Want to know more?
Updated: 06/09/2020 by
You cannot open Microsoft Word in a command line, but you can start Microsoft Word from the command line by following the steps below.
Note
Microsoft Word is a Windows program and cannot display a Word document in the Windows command line window. If you need a document to be viewed in the command line window, we suggest saving the document as a text file.
Opening document from the command line
- Open the Windows command line.
- Get to the directory containing the Microsoft Word document using the cd command.
- Once in the directory containing the document, use the start command to start the document in Windows. For example, if the document is called «example.doc,» you would type the following command.
start example.doc
Once the command above is run, if the file «example.doc» existed in the current directory, it would open Microsoft Word and then show the document.
Tip
Using the start command in a batch file is a way of opening a document for the user to read after an install.
Opening Microsoft Word from the command line
If you want to open Microsoft Word by itself without opening a document, you’ll first need to determine where the directory containing winword.exe is located by following the steps below.
- Open the Windows command line.
- Type the following command to get into the «Program Files (x86)» directory.
cd "Program Files (x86)"
- From the C:Program Files (x86) directory, type the command below to find the directory containing the winword.exe file.
dir winword.exe /s
- After the command above is typed, the computer searches for the file and a few seconds later it should list the directory containing «winword.exe.» For example, it may give a directory similar to the example output shown below.
Directory of C:Program Files (x86)Microsoft OfficeOffice14
- Once we know the directory, we can get into the directory using the cd command and the name of the directories. For example, to get into the above path from the Program Files (x86) directory, we’d type the following command.
cd Microsoft OfficeOffice14
- Finally, once the prompt shows the proper directory, typing winword opens Microsoft Word in Windows from the command line.
Download PC Repair Tool to quickly find & fix Windows errors automatically
Microsoft Word has several useful command-line switches that can be used to start Word. These switches can be used to make Word run in a specific way or perform specific tasks – like if you want to start it in the Safe Mode without any addons.
To open a Word document using the switches in Windows 10/8/7, type winword.exe /x. Here “/x” is the switch.
To modify how Microsoft Office Word starts on a one-time basis, you can add switches to the Microsoft Windows Run command (Start menu).
The following is the list of switches for Microsoft Word:
Switch and parameter | Description |
---|---|
/safe | Starts Word in Safe Mode. |
/q | Starts Word without displaying the Word splash screen. |
/ttemplatename | Starts Word with a new document based on a template other than the Normal template.
Example To start Word with a document based on a template called Myfax.dotx, stored on the C drive, type the following at the command prompt: /tc:Myfax.dotx Note: Do not include a space between the switch and the name of the template file. Security Note: Because templates can store macro viruses, be careful about opening them or creating files based on new templates. Take the following precautions: run up-to-date antivirus software on your computer, set your macro security level to high, clear the Trust all installed add-ins and templates check box, use digital signatures, and maintain a list of trusted sources. |
/t filename | Starts Word and opens an existing file.
Example To start Word and open the template file Myfax.dotx, stored on the C drive, type the following at the command prompt: /t c:Myfax.dotx Example To start Word and open multiple files, such as MyFile.docx and MyFile2.docx, each stored on the C drive, type the following at the command prompt: /t c:MyFile.docx c:MyFile2.docx |
/f filename | Starts Word with a new document based on an existing file.
Example To start Word and create a new document based on file MyFile.docx, stored on the desktop, type the following at the command prompt: /f “c:Documents and SettingsAll UsersDesktopMyFile.docx” |
/h http://filename | Starts Word and opens a read-only copy of a document that is stored on a Microsoft Windows SharePoint Services site. The site must be on a computer that is running Word 2007 or later or Windows SharePoint Services 2.0 or later.
Example To start Word and open a copy of file MyFile.docx, stored in a document library at the URL http://MySite/Documents, type the following at the command prompt: /h http://MySite/Documents/MyFile.docx Note: If the document is checked out to you, the /h switch has no effect. Word opens the file so that you can edit it. |
/pxslt | Starts Word and opens an existing XML document based on the specified Extensible Stylesheet Language Transformation (XSLT).
Example To start Word and apply the XSLT MyTransform, stored on the C drive, to the XML file Data.xml, also stored on the C drive, type the following at the command prompt: /pc:MyTransform.xsl c:Data.xml |
/a | Starts Word and prevents add-ins and global templates (including the Normal template) from being loaded automatically. The /a switch also locks the setting files. |
/ladd-in | Starts Word and then loads a specific Word add-in.
Example To start Word and then load the add-in Sales.dll, stored on the C drive, type the following at the command prompt: /lc:Sales.dll Note: Do not include a space between the switch and the add-in name. Security Note: Use caution when running executable files or code in macros or applications. Executable files or code can be used to carry out actions that might compromise the security of your computer and data. |
/m | Starts Word without running any AutoExec macros. |
/mmacroname | Starts Word and then runs a specific macro. The /m switch also prevents Word from running any AutoExec macros.
Example To start Word and then run the macro Salelead, type the following at the command prompt: /mSalelead Note: Do not include a space between the switch and the macro name. Because macros can contain viruses, be careful about running them. Take the following precautions: run up-to-date antivirus software on your computer; set your macro security level to high; clear the Trust all installed add-ins and templates check box; use digital signatures; maintain a list of trusted publishers. |
/n | Starts a new instance of Word with no document open. Documents opened in each instance of Word will not appear as choices in the Switch Windows list of other instances. |
/w | Starts a new instance of Word with a blank document. Documents opened in each instance of Word will not appear as choices in the Switch Windows list of the other instances. |
/r | Re-registers Word in the Windows registry. This switch starts Word, runs Office Setup, updates the Windows registry, and then closes. |
/x | Starts Word from the operating system shell so that Word responds to only one Dynamic Data Exchange (DDE) request (for example, to print a document programmatically). |
/ztemplatename |
Visibly behaves exactly like the /t switch. However, you can use the /z switch with Word to generate both a Startup and a New event, whereas the /t switch generates only a Startup event. |
If you plan to use a modified startup method frequently, you can create a shortcut on the Windows desktop, using these switches.
You can get the command line switches for Word, Excel, PowerPoint, Outlook and Access here at KB210565.
Anand Khanse is the Admin of TheWindowsClub.com, a 10-year Microsoft MVP (2006-16) & a Windows Insider MVP (2016-2022). Please read the entire post & the comments first, create a System Restore Point before making any changes to your system & be careful about any 3rd-party offers while installing freeware.
on February 8, 2012
We can launch Microsoft Word application from run window by running the command winword.
Open MS word from Run window
Note that this command does not work from command line as winword.exe
location is not added to the PATH environment variable. However, we can use the below command to open Word application from command prompt.
start winword
The above commands work with all editions of MS Word and Office.
To open an existing word document from command prompt
start winword
For example, to open the file C:UsersmyloginResume.docx
, the command would be
start winword C:UsersmyloginResume.docx
As a Linux user, there are times when you have to play nicely with users of Windows or Mac OS — such as when they send you Microsoft Word files. When you receive a Word file, you can either follow Richard Stallman’s advice and refuse it, or bite the bullet and work with it. Modern Linux word processors — such as OpenOffice.org Writer, AbiWord, KWord, and TextMaker — can deal with most Word files. But if you don’t want to fire up a word processor in order to read or print the document, you can turn to the command line. A handful of small but powerful Linux command line utilities make viewing, printing, and even converting Word files to another format a breeze.
Antiword
Antiword is a nifty application that can convert Word documents to plain text, PostScript, and PDF. According to the developer, conversion to DocBook XML is still experimental and doesn’t always work well.
Antiword is very flexible. It can read and convert files created with Word versions 2.0 to 2003, and you can run it on multiple operating systems, including Linux, Mac OS X, RISC OS, FreeBSD, and OpenVMS. On top of that, you can set the paper size for documents converted to PostScript or PDF, include any text that was removed from the file (but which Word notoriously keeps a record of), and display any hidden text.
For the most part, you’ll just want to view a Word document. To do that, you just have to type the following command:
antiword file.doc
The Word document will be converted to text and printed to the screen. If you’re running Antiword in a terminal window, you’ll have to scroll up to view the full text of the document. To get around this, you can pipe the output from Antiword to the less utility, which will allow you to scroll through the document page by page from the top:
antiword file.doc | less
Catdoc
Slightly less flexible than Antiword, but still useful, is Catdoc, whose developer explains that “it does same work for .doc files as the Unix cat command for plain ASCII files.”
While Antiword tries to retain some of the formatting of a Word file, Catdoc is a quick and dirty tool. It outputs either LaTeX or plain text, and little else. The LaTeX output leaves a lot to be desired — it does nothing beyond adding the LaTeX formatting for tables or special characters. You’ll have to add the LaTeX preamble and any other formatting code yourself.
Catdoc has some rudimentary support for tables. If it’s converting a simple table, the output will be passable. If the table is more complex, say with nested elements, it won’t be pretty.
To run Catdoc, type the following command:
catdoc <output_format> filename.doc
You can specify the output format using the -a
(text) or -t
(LaTeX) option. So, to convert the Word file whitepaper.doc to text, type:
catdoc -a whitepaper.doc
As with Antiword, you can pipe the output from Catdoc to the less utility.
wvWare
wvWare is part of of wv, a library of that enables developers to code software that can read and write Word files. In fact, both AbiWord and KWord use wv for importing Word documents. wvWare can handle documents created with Word from version 6 to 2000. It converts Word 2.0 documents to text only.
Used by itself without any command line options, wvWare will convert a Word document to HTML and display the code on the screen. If you want to write the HTML to a file, use the following command:
wvWare file.doc > file.html
But you’re not stuck with HTML. wvWare comes with a set of scripts that can convert Word files to a number of other formats, including plain text, HTML, LaTeX, PDF, PostScript, LaTeX DVI, and WML. These scripts are usually installed in the folder /usr/bin. You can get a list of them by typing ls /usr/bin/wv*
at the command line.
If you want to convert a Word document to text, use the following command:
wvText file.doc file.txt
I’ve never been able to pipe the output to the less utility or a text editor. I’ve always had to open a file converted with wvWare in an editor or browser.
you can view Word files using wvWare and the w3m text-mode Web browser, as detailed in the book Linux Desktop Hacks . I’ve tried this hack with the text-based browsers Lynx and Links as well, but w3m does the best job out of the three.
To use this hack, type the following command:
wvWare -x /usr/lib/wv/wvHtml.xml file.doc | w3m -T text/html
You can also encapsulate the above command in a script if you decide to use this hack regularly. wvWare converts the Word file to HTML using the configuration file named wvHtml.xml, then pipes the output to the w3m browser.
A gotcha or two
While Antiword, Catdoc, and wvWare do a good job handling most Word files, you might run into documents that don’t want to cooperate with you. I’ve found that these utilities sometimes can’t process documents that are saved with Word’s Fast Save feature, which quickly saves a file by tacking any changes to the end of the file. For example, Antiword might display the cryptic message The Small Block Depot is damaged
when it encounters a Fast Saved file. This doesn’t happen with all Fast Saved files, however.
As well, out of the box these programs might display garbage characters when converting Word files that use non-Latin character sets or that contain graphics. Check the documentation for the program that you’re using for information on how to deal with character sets and graphics.
You don’t need a word processor to view Microsoft Word documents on Linux. With the right command line apps, you can view or print those files in a flash with just a few keystrokes.
Scott Nesbitt is a Toronto-based technical writer and journalist who is a big fan of useful little command-line utilities.
Please Note:
This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Opening a Text File and Template from the Command Line.
Written by Allen Wyatt (last updated August 27, 2021)
This tip applies to Word 2007, 2010, 2013, and 2016
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 FilesMicrosoft OfficeOfficeWinword.exe" "d:text.txt" /t"MyTemplate.dotm"
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 because it knows that template files don’t go with text files. Instead, Word opens the file with the Normal template. 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 the Normal template 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 template as something else (such as OldNormal.dotm) and then rename the template you want to use as Normal.dotm. When you open the text file from the command line, the desired set of styles will be in the new Normal.dotm 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 .UpdateStylesOnOpen = False .AttachedTemplate = "d:test filesMyTemplate.dotm" .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 FilesMicrosoft OfficeOfficeWinword.exe" "d:text.txt" /m"TextTempate"
In this case, the text file is opened and the TextTemplate macro is run. This works because Normal.dotm (where the TextTemplate macro is stored) is attached to the text file, and then the macro attaches the other template automatically.
If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I’ve prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.
WordTips is your source for cost-effective Microsoft Word training.
(Microsoft Word is the most popular word processing software in the world.)
This tip (11187) applies to Microsoft Word 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Word here: Opening a Text File and Template from the Command Line.
Author Bio
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. Learn more about Allen…
MORE FROM ALLEN
Resetting Default Character Formatting
If you need to remove any explicit character formatting from some text, you’ll want to commit the shortcut in this tip to …
Discover More
Changing How Word Presents Your Document
Tired of the old black-on-white text displayed by Word? Depending on your program version, you can configure Word to show …
Discover More
Protecting Conditional Formatting
When you apply conditional formatting to the cells in your worksheet, those rules can seem a bit fragile at times. For …
Discover More