In my office, we have some "Word Wizards" , the "CHOSEN ONES" those write add-ins for Microsoft Office applications. Mainly Ms-Office add-ins written in either, in-built visual.net code or by using VSTO in visual studio.
Last week, I have an friendly argument with one of "Wizard" in my office, about, PowerShell and Word. I told him, that we can do almost anything with PowerShell and He said " Can you Automate Office applications?" and I replied as "YES" (OOPS).
And that, the day, when our battle started, he keep asking me to to do this and that, and I was trying to figure out "How to do that", sometimes, if feels like "Gandalf" and "Dumbledore" are fighting with each other.
But, these fighting ( not literally) comes out as very educating and for me :) . So, I planned to write articles about it. I am sure, that you will learn something from this too.
Today, we are going to see, that how can we open Microsoft Word using PowerShell.
Our first task is to open Microsoft word, and we are going to use the COM object for it. Name of the Word's COM object is "Word.Application". and we have to use the New-Object cmdlet, to map com object to the variable.
$word = New-Object -ComObject "Word.Application"
After that, we have to set the Visible property of $word as true, otherwise we won't be able to see word.
$word.Visible = $true
After that, we jus need to type our variable $word and hit enter to open Microsoft Word.
You may see a lot's of Output after running $word variable, you can omit that output by adding pipe and Out-Null variable.
$word | Out-Null
In , next blog post we will see, we will deal with word documents :) , Stay tunes for more, and thanks for reading the blog post.
Aman Dhally
If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube” channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.