Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8882305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:32:42+00:00 2026-06-14T20:32:42+00:00

Recently I’am experimenting with different API’s for MS Word file management (writing for now).

  • 0

Recently I’am experimenting with different API’s for MS Word file management (writing for now). At this point I need just a simple writing python API. I tried win32com module which prove to be very robust with lack of examples for python online (very little knowledge of VB and C to be able to translate examples from MSDN).

I tried to use python-docx but after install I am getting this traceback for any docx function.

Traceback (most recent call last):
  File "C:\filepath.py", line 9, in <module>
    ispit = newdocument()
NameError: name 'newdocument' is not defined

I had some problems with installation of lxml by source and by easy_install. It was checking for libxlm2 and libxslt binaries. I downloaded them and added environmental paths but the installation trough source or easy_install stopped every time.

Finally I used unofficial python extension package from this site Link.
Installation was fast and there was no errors in the end.

Is there something I can do to make docx work and is there some python win32com related references online? I couldn’t find any. (except MSDN(VB not python) and O’Reily’s Python programming on win32)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:32:44+00:00Added an answer on June 14, 2026 at 8:32 pm

    When using win32com, bear in mind that you are talking to the Word object model. You don’t need to know a lot of VBA or other languages to apply the samples to using Python; you just need to figure out which parts of the object model are being used.

    Let’s take the following sample (in VBA) which will create a new instance of the Application, and load a new document into that new instance:

    Public Sub NewWordApp()
    
        'Create variables to reference objects
        '(This line is not needed in Python; you don't need to declare variables 
        'or their types before using them)
        Dim wordApp As Word.Application, wordDoc As Word.Document
    
        'Create a new instance of a Word Application object
        '(Another difference - in VBA you use Set for objects and simple assignment for 
        'primitive values. In Python, you use simple assignment for objects as well.)
        Set wordApp = New Word.Application
    
        'Show the application
        wordApp.Visible = True
    
        'Create a new document in the application
        Set wordDoc = wordApp.Documents.Add()
    
        'Set the text of the first paragraph
        '(A Paragraph object doesn't have a Text property. Instead, it has a Range property
        'which refers to a Range object, which does have a Text property.)
        wordDoc.Paragraphs(1).Range.Text = "Hello, World!"
    
    End Sub
    

    A similar snippet of code in Python might look like this:

    import win32com.client
    
    #Create an instance of Word.Application
    wordApp = win32com.client.Dispatch('Word.Application')
    
    #Show the application
    wordApp.Visible = True
    
    #Create a new document in the application
    wordDoc = wordApp.Documents.Add()
    
    #Set the text of the first paragraph
    wordDoc.Paragraphs(1).Range.Text = "Hello, World!"
    

    Some links to the Word object model:

    • Application object
    • Documents collection
    • Document object
    • Paragraphs collection
    • Paragraph object
    • Range object
    • Concepts

    Some Python examples:

    • Python and Microsoft Office – Using PyWin32
    • Use Python to parse Microsoft Word documents using PyWin32 Library
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently, I was writing a class in which I discovered that I could reduce
Recently I have released my app into the US AppStore. Now I Planed for
recently, while working on a db2 -> oracle migration project, we came across this
Recently, I had the need for a function that I could use to guarantee
Recently, I've started experimenting with Mercurial, due to the fact that it always attracted
Recently I worked in a project in where I need to display japanese text
Recently I started reading (just a bit) the current draft for the future C++11
Recently I changed the hostname of my computer and now every time I start
Recently I encountered this puzzle : int main(){ int arr[7]; int b,c,d,a; a=4; printf(%d,arr[?]);
Recently me and my team got a HG repository for versioning as this would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.