Tuesday, November 17, 2015

PowerShell & Microsoft Word 2016 : Creating new Word 2016 file using Word Templates.

 

In our previous blog post, we have see, that how can we create a new word file using PowerShell. Today we are going to see, that , how can we create a new word file using Word templates.

Word templates are pre-formatted word documents, which you can use as an boilerplates. The default extension of the Word Templates are .dotx.

The default location of templates is : %appdata%\Microsoft\Templates\

I have downloaded a word templates from internet and we are going to create a new document by using this template. 

$myWordTemplate = 'C:\Users\aman.dhally\AppData\Roaming\Microsoft\Templates\Flower personal business cards.dotx'

 

In the above line, I am creating a variable which stores the file location of my template. The rest of the code is as same as the pervious one , except , in the add() method, we have to provide the name of the above file , simple ;o) .

 

The complete code is :

 

#B3

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

$word.Visible = $true

$myWordTemplate = 'C:\Users\aman.dhally\AppData\Roaming\Microsoft\Templates\Flower personal business cards.dotx'

$word.Application.Documents.Add($myWordTemplate) | Out-Null

 

and here is the output.

 

Aman Dhally - Manya kaur

 

 

tumblr_lh6weimfMc1qc47qq

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

Note: Only a member of this blog may post a comment.