Monday, November 16, 2015

PowerShell & Microsoft Word 2016 : Create new blank new Word 2016 document using PowerShell.

 

In my previous post, we have seen, that how can we open Microsoft Word 2016 Desktop application using PowerShell.

Today, we are going to see,how can we create a new Word 2016 document using PowerShell. All of our code is based on the pervious code. We need to create a Word.Application COM object and make it visible.

$word = New-Object -ComObject "Word.Application"

$word.Visible = $true ;

Now, we have to use the application namespace in $word variable, and use it's add() method to create a blank word 2016 document.

$word.Application.Documents.Add();

and runt he above code and you will see a a word opening with a blank document :) .

The complete code to create a blank word document is

#Complete code to cretae a new document

$word = New-Object -ComObject "Word.Application"

$word.Visible = $true

$word.Application.Documents.Add();

Try it :)

Aman Dhally - Manya Kaur

With Regards.
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