Windows Vista Forums

[REF] ?????
  1. #1


    Kuma Guest

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

      My System SpecsSystem Spec

  2. #2


    Kirk Munro Guest

    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

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


      My System SpecsSystem Spec

  3. #3


    Marco Shaw [MVP] Guest

    Re: [REF] ?????

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

      My System SpecsSystem Spec

  4. #4


    Kuma Guest

    Re: ?????

    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?

      My System SpecsSystem Spec

  5. #5


    Marco Shaw [MVP] Guest

    Re: ?????


    > 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

      My System SpecsSystem Spec

[REF] ????? problems?