Monthly Archive

Categories

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.

Leave a Reply