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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:11:16+00:00 2026-06-08T12:11:16+00:00

Using Access 2010, WinXP. I’m trying to iterate through a collection of folders, collecting

  • 0

Using Access 2010, WinXP. I’m trying to iterate through a collection of folders, collecting values from each of the Excel files in each folder to add to a table in my database. The problem is that even though I’m closing the workbook each time, it must not be closing fast enough, because if the same filename appears in two consecutive folders, I get an error message:

Run-time error '1004':
A document with the name 'someWorkbook.xls' is already open.

Here’s my code:

sub traverse()

Dim fso As filesystemobject
Dim fObj As File
Dim fldObj As Folder
Dim fCol As Files
Dim xlApp As Excel.Application
dim xlBk as Excel.Workbook

Set xlApp = New Excel.Application
Set fso = New filesystemobject
For Each fldObj In fso.GetFolder("c:\basePath").SubFolders
    Set fCol = fldObj.Files
    For Each fObj In fCol
        If UCase(Left(fso.GetExtensionName(fObj.Name), 3)) = "XLS" Then
           Set xlBk=xlApp.workbooks.open(fObj.path)
           getData(xlBk)
           xlBk.close false
           DoEvents
        End If
    Next
Next

End Sub

I tried quitting the Excel instance and starting a new one in the For Each fObj loop, as follows:

set xlApp=new Excel.Application
Set xlBk=xlApp.workbooks.open(fObj.path)
getData(xlBk)
xlBk.close false
DoEvents
xlApp.quit
DoEvents

but that only ended up opening a whole bunch of Excel instances without quitting them, as when it crashed I checked the task manager and found about 30 Excel instances.

Is there something else I can do to guarantee that my code doesn’t proceed until the Excel action triggered by .Close or .Quit has completed?

  • 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-08T12:11:16+00:00Added an answer on June 8, 2026 at 12:11 pm

    @sigil Answered his own question in comments.

    I found the problem. It was due to a piece of code that I didn’t post; the calls to workbooks.open and workbook.close actually happen inside getData, where there is an if-then clause that exits getData without closing the workbook. I added a workbook.close before exit function and it is behaving properly now. Sorry for not posting the code as-is, I thought it would be easier to get help if I simplified it. Next time I’ll know better.

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

Sidebar

Related Questions

I'm using Access 2010. I have a database with multiple tables, each containing different
I am trying to access the data from MS Access Database using C#. in
I am trying to connect to access 2010 database using the following string connection.
I'm trying to update a local Access 2010 table by pulling data from a
Using Access 2003 I want to get a table value from the two databases
I am using the DoCmd.TransferText in MS-Access-2010 VBA to export a table to a
I have a Microsoft Access 2010 database(*). Now, using Visual Studio 2010, I want
I'm using Access 2010 under Win7. I've discovered I can dimension my arrays at
I am using C# with MS Access 2010. I need to retrieve the table
I am importing an excel file into Access 2010 and the date field(CALLDATE) comes

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.