How to run a Word Macro via Python?

Asked

Viewed 85 times

0

import os
import comtypes.client

path=r"path to the .docm file where I saved the vba macro"

word=comtypes.client.CreateObject("Word.Application")
word.Documents.Open(path,ReadOnly=1)
word.Run("Project.Modulo1.ConvertDoc")
word.Documents(1).Close(SaveChanges=0)
word.Application.Quit()
wd=0

I tried that, but I got the following mistake:

"NULL COM Pointer Acess"

  • Looking at the code, I think it’s correct. I suggest a check on the macro file address, macro name inside the file and macro internal location inside the file

  • I’m receiving: "NULL COM Pointer Acess" , do you know any tutorial for run word macro with python? I found enough information for Excel Macro, but I’m not able to adapt to word.

  • Which line points this error?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.