Word New Document change

I started experimenting with the New-WordDocument function and realised I needed to change it to make the variables usable across the functions.

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

 

Simple change is to make the variables global in scope.  This means they are available across the functions of the module and form with scripts and from the prompt.

Depending on what you want to do you may not need this change but as I want to eventually use the module functions from scripts it works for me.

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