Word, PoSH and getting info on what can be used

Welcome Forums General PowerShell Q&A Word, PoSH and getting info on what can be used

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years ago.

  • Author
  • #5507

    Points: 0
    Rank: Member

    by CarlWebster at 2013-02-04 09:38:24

    I am using Jeff Hick's Demoe-WordReport.ps1 Word PoSH sample code from http://jdhitsolutions.com/blog/2012/05/ ... and-demos/ .

    There is one line that is not working for non us-EN versions of Word 2007 or 2010 or 2013.

    Here is my sample code to get the error.

    $Word = New-Object -comobject "Word.Application"
    $Word.Visible = $False
    $WordVersion = $Word.Version
    If ( $WordVersion -eq 12)
    $BuildingBlocks=$word.Templates | Where {$_.name -eq "Building Blocks.dotx"}
    $BuildingBlocks=$word.Templates | Where {$_.name -eq "Built-In Building Blocks.dotx"}
    #this line error out in say French Word 2013
    $toc=$BuildingBlocks.BuildingBlockEntries.Item("Automatic Table 2")

    The error received is:

    Exception lors de l'appel de « Item » avec « 1 » argument(s) : « Le membre de la collection requis n'existe pas. »
    Au niveau de C:\XA65_Inventory_V3_Signed.ps1 : 533 Caractère : 47
    + $toc=$BuildingBlocks.BuildingBlockEntries.Item < <<< ("Automatic Table 2")
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

    How do I find out what I can use for $BuildingBlocks.BuildingBlockEntries.Item()?

    $x = $BuildingBlocks.BuildingBlockEntries
    $x | gm

    TypeName: System.__ComObject#{39709229-56a0-4e29-9112-b31dd067ebfd}

    Name MemberType Definition
    —- ———- ———-
    Add Method BuildingBlock Add (string, WdBuildingBlockTypes, string, Range, Variant, WdDocPartInsertOptions)
    Item Method BuildingBlock Item (Variant)
    Application Property Application Application () {get}
    Count Property int Count () {get}
    Creator Property int Creator () {get}
    Parent Property IDispatch Parent () {get}

    $x = $BuildingBlocks.BuildingBlockEntries.item
    $x | gm

    TypeName: System.Management.Automation.PSMethod

    Name MemberType Definition
    —- ———- ———-
    Copy Method System.Management.Automation.PSMemberInfo Copy()
    Equals Method bool Equals(System.Object obj)
    GetHashCode Method int GetHashCode()
    GetType Method type GetType()
    Invoke Method System.Object Invoke(Params System.Object[] arguments)
    ToString Method string ToString()
    IsInstance Property System.Boolean IsInstance {get;}
    MemberType Property System.Management.Automation.PSMemberTypes MemberType {get;}
    Name Property System.String Name {get;}
    OverloadDefinitions Property System.Collections.ObjectModel.Collection`1[[System.String, mscorlib, Version=
    TypeNameOfValue Property System.String TypeNameOfValue {get;}
    Value Property System.Object Value {get;set;}

    Where do I go from here in finding out what "Automatic Table 2" is in the French version of Word?



    by DonJ at 2013-02-04 10:31:26

    As a note, please use the CODE button to format your code. It's a lot easier to follow that way.

    I'm unfortunately not able to read the non-English error, and I don't have a non en-US system on which to test. So I'm guessing, here. My best suggestion is for you to consult the documentation for the COM object. It begins at http://msdn.microsoft.com/en-us/library ... 80%29.aspx, and if there are any differences with non-US systems, those would have to be documented there or they're not documented at all.

    by CarlWebster at 2013-02-04 11:07:14

    A friend pointed me in the right direction. This is what I came up with and it works.

    $Entries = $BuildingBlocks.BuildingBlockEntries
    $count = $entries.count
    For($i = 1; $i -lt $count; $i++)
    $entry = $entries.item($i).name
    write-host $entry

    I hope I am not going to hell for using write-host in this example! 🙂

    For us non programmers, figuring out this Word comObject stuff is not easy.


The topic ‘Word, PoSH and getting info on what can be used’ is closed to new replies.