Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

[REF] ?????

Closed Thread
 
Thread Tools Display Modes
Old 12-16-2007   #1 (permalink)
Kuma
Guest
 
Posts: n/a

[REF] ?????

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.
 
Old 12-17-2007   #2 (permalink)
Kirk Munro
Guest
 
Posts: n/a

Re: [REF] ?????

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
Poshoholic
http://poshoholic.com


"Kuma" <kumasan76@xxxxxx> wrote in message
news:2c32087b-46e8-415e-a369-f59d2bcd7e72@xxxxxx
Quote:

> 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.

 
Old 12-17-2007   #3 (permalink)
Marco Shaw [MVP]
Guest
 
Posts: n/a

Re: [REF] ?????

Kirk Munro wrote:
Quote:

> 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.
>
Office 2007 SP1 was released just last week...

I'll try to get it maybe overnight.

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
 
Old 12-17-2007   #4 (permalink)
Kuma
Guest
 
Posts: n/a

Re: ?????

On Dec 17, 8:27 pm, "Kirk Munro" <so...@xxxxxx> wrote:
Quote:

> 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
>
>
>
Quote:

> > 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)
>
Quote:

> > 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???
>
Quote:

> > 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?
 
Old 12-18-2007   #5 (permalink)
Marco Shaw [MVP]
Guest
 
Posts: n/a

Re: ?????

Quote:

> 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?
I think you may have to go ask this in a Office newsgroup. From what I
can tell, the only way to easily access Office via .NET (C#, PowerShell,
etc.) is via the COM object, which is what you're doing.

It seems even when you get the Office SDK, this is how any .NET language
is used for Office programming.

Marco
 
 
Closed Thread

Thread Tools
Display Modes









Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49