Categories

Word Close Document

So far we have created a document and started to add data into the document.

001
002
003
004
005
006
007
008
function Close-WordDocument {
    param (
        [parameter(Mandatory=$true)]
        [string]$file
    )
    $doc.SaveAs([REF]$file)
    $word.Quit()
}

 

We pass a file name in as a parameter. Notice that the parameter is mandatory. If we don’t supply the file name we will be prompted. If just a file name is given it will be saved into your standard word location (usually My Documents). If you want it to save somewhere else then use the full path.

The SaveAs() method is used for the save.  If you give the name of a file that exists it will overwrite!

The final line of the script closes the Word application.

Technorati Tags: ,

Leave a Reply