How Can I run python script from word add-in?

YaoZong Wang (汪耀宗) 1 Reputation point
2022-09-18T16:11:37.073+00:00

How Can I run python script from word add-in?

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,844 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Dillon Silzer 57,231 Reputation points
    2022-09-18T18:13:12.613+00:00

    Hi @YaoZong Wang (汪耀宗)

    It looks like you can invoke python utilizing VBAs Shell function (as seen in https://stackoverflow.com/questions/3815340/running-python-scripts-from-ms-office). I don't believe there is a Microsoft Word Add-in that can do this so you may have to resort to the script below.

    Sub RunExternalProg()  
      
        Dim return_value As Double  
        return_value = Shell("C:\PathToPython\pythonw.exe C:\my_script.py", vbHide)  
        Debug.Print return_value  
      
    End Sub  
    

    (Answer by mechanical_meat)

    ------------------------------------

    If this is helpful please accept answer.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.