Word Macro Powershell Script Broken

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Matt Bloomfield Matt Bloomfield 6 months, 2 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36728
    Profile photo of Brennan Fulmer
    Brennan Fulmer
    Participant

    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
    $doc.Close()
    $word.Quit()

    #36737
    Profile photo of Matt Bloomfield
    Matt Bloomfield
    Participant

    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.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.