header image

Word New Document change

Posted by: | August 30, 2009 | No Comment |

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

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.

under: PowerShellV2