Word New Document

Lets add another function to our module for working with Word.  Its time to create a new word document

001
002
003
004
005
function New-WordDocument {
    $word = New-Object -ComObject Word.Application
    $word.Visible = $true
    $Word.Documents.Add() | Out-Null
}

 

Create the object for word as before.  Set the visible property to true (we can’t use it if we can’t see it)  We then add a document.  The Out-Null I found was necessary on my Windows 7 & Office 2010 combination because a lot of stuff was generated that I didn’t want to see.  Try it without on other combinations.  I don’t remember it being so bad with Word 2007

Advertisements
This entry was posted in PowerShell V2. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s