On Dec 17, 8:27 pm, "Kirk Munro" <so...@xxxxxx> wrote:
> Did you install any patches or service packs for Word or did you upgrade
> office? It could be that a change external to PowerShell caused this.
>
> --
> Kirk Munro
> Poshoholichttp://poshoholic.com
>
> "Kuma" <kumasa...@xxxxxx> wrote in message
>
> news:2c32087b-46e8-415e-a369-f59d2bcd7e72@xxxxxx
>
>
>
> > I'm on XP SP2 with PowerShell V1. I have a script that has worked
> > perfectly until now. When I ran it today it threw up all over my
> > screen. I went line by line through it and found the offending line.
> > $Word = New-Object -Com Word.Application
> > #$files is an array of files.
> > #$Savepath is the path to the files
> > #Do some Stuff
> > $SAVENAME=$SAVEPATH+'\'+$FILES[$I].BASENAME+'.DOC'
> > ################OFFENDING LINE BELOW##############
> > $Word.ACTIVEDOCUMENT.SAVEAS($SAVENAME) >
> > I get an error telling me i need to use [ref] if i change that line to
> > $Word.ACTIVEDOCUMENT.SAVEAS([ref]$SAVENAME)
> > It's fine. Ok great why did it break after months of no problems if I
> > didn't change anything??? >
> > Thanks for any insights.- Hide quoted text - >
> - Show quoted text - Ok I think I found it I just don't know how to fix it. While working
on a C# project I needed the Office Interop Classes. Now if I do the
following:
$word = New-Object -Comobject Word.Application
$word.gettype()|Select Assembly,Namespace
I get back:
Assembly: Microsoft.Office.Interop.Word, Version=10.0.4504.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35
Namespace: Microsoft.Office.Interop.Word
So it looks to me like New-Object is creating an instance of
word.application from the Interop which is causing me to have to use
[ref]. So how to I create a standard word.application without it
coming from the Interop?