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 6048143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:25:49+00:00 2026-05-23T07:25:49+00:00

I open several different workbooks (excel xlsx format) in COM, and mess with them.

  • 0

I open several different workbooks (excel xlsx format) in COM, and mess with them. As the program progresses I wish to close one specific workbook but keep the rest open.

How do I close ONE workbook? (instead of the entire excel application)

xl = Dispatch("Excel.Application")
xl.Visible = False
try:
    output = xl.Workbooks.Open(workbookName)
    output2 = xl.Workbooks.Open(workbook2Name)
except com_error:
    print "you screwed up blahblahblah"
    exit()

#work on some stuff
#close output but keep output2 open
  • 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-05-23T07:25:50+00:00Added an answer on May 23, 2026 at 7:25 am

    The the Workbook COM object has a Close() method. Basically, it should be something like:

    xl = Dispatch('Excel.Application')
    wb = xl.Workbooks.Open('New Workbook.xlsx')
    # do some stuff
    wb.Close(True) # save the workbook
    

    The above was just a skeleton here’s some code that works on my machine against Office 2010:

    from win32com.client import Dispatch
    xl = Dispatch('Excel.Application')
    wb = xl.Workbooks.Add()
    ws = wb.Worksheets.Add()
    cell = ws.Cells(1)
    cell.Value = 'Some text'
    wb.Close(True, r'C:\Path\to\folder\Test.xlsx')
    

    Of course, that creates a new xlsx file. But then I’m able to successfully open and modify the file in the same session as follows:

    wb = xl.Workbooks.Open(r'C:\Path\to\folder\Test.xlsx')
    ws = wb.Worksheets(1)
    cell = ws.Cells(2)
    cell.Value = 'Some more text'
    wb.Close(True)
    

    Don’t know if any of that helps…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several projects open in an Eclipse workspace. Like so: com.harbl.project.one com.harbl.project.two com.harbl.project.three
If I have several OS-X Terminal.app windows open, how can I move one Terminal
I've tried several different connection strings and always get the same error: Format of
I have several different processes and I would like them to all log to
do you know how can one in Textmate open several windows for the same
I open several files in Vim by, for example, running vim a/*.php which opens
I'm looking for a JS library that will allow me to open several images
I use svn:externals to reference several open source projects. I then make some local
I have several small open-source projects that I wrote. All my attempts to find
I am currently investigating several free/open source OpenGL based 3D engines, and was wondering

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.