If you're open to using Powershell instead of the command prompt, you can complete with just a couple of setup steps.
First, create the environment variable for your word document. If you've already done this elsewhere, skip this step. Note that strings that are enclosed by double quotations will resolve variables, so in this example $env:username
will resolve to your current Windows user. You could hard-code that too if you like, but this is helpful to generalize the example.
$env:WordDoc = "C:\Users\$env:username\Documents\myDocument.docx"
Next, you will need to add Office's directory to your path variable. You can search for winword.exe to find the location, but it will probably be one of the two below:
- C:\Program Files\Microsoft Office\Office14
- C:\Program Files (x86)\Microsoft Office\Office14
You can simply append that path to the environment variable, like so:
$env:Path += ";C:\Program Files\Microsoft Office\Office14"
Anyway, once that is set you can use winword
from powershell to open word documents. Here's a simple example:
winword $env:WordDoc
A quick note about changing environment variables in this manner -- they are on the process level. That means that these changes will go away when you close your powershell session. Instead of typing them out each new session, you could save them to a powershell script and run that in the console. Here's a quick script that works on my machine:
param
(
[string]$FilePath
[string]$wordDir = "C:\Program Files (x86)\Microsoft Office\Office14"
)
$env:WordDoc = $FilePath
If(!($env:Path | Select-String -SimpleMatch $wordDir))
{
$env:Path += ";$wordDir"
}
winword $env:WordDoc
Doing this in the command prompt would involve a similar procedure -- you still need to set your PATH environment variable to recognize Microsoft Office. This answer offers some insight on how to do that.