Word Macro Powershell Script Broken

This topic contains 1 reply, has 2 voices, and was last updated by  Matt Bloomfield 2 years, 3 months ago.

  • Author
  • #36728

    Brennan Fulmer

    I wrote a script to check for Excel Macro's that returns TRUE if a document contains a macro. I then wanted to reuse the code of Word Macro's but its returning false even for documents I created a macro in (see code below). What am I doing wrong?

    $word = new-object -comobject word.application
    $doc = $word.documents.Open("C:\Path\example.docm")
    Echo $doc.HasVBProject

  • #36737

    Matt Bloomfield

    Check that you actually created the macro in the document example.docm.

    I was testing your code (which works fine) and it took me a few goes to realise that when I was creating the Word macro it was actually inserting it in normal.dotm, not in the test document. Use the Macros in: drop down to change where you're putting the macro.

You must be logged in to reply to this topic.