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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:48:57+00:00 2026-06-01T12:48:57+00:00

I have written a VBA macro in an excel spreadsheet that opens all workbooks

  • 0

I have written a VBA macro in an excel spreadsheet that opens all workbooks in a specific location and pulls data out of those workbooks and validates and copies it to the active workbook. It then opens the next workbook in the directory and repeats the process until all files in the directory have been read through.

Everything works, except I cant seem to get the target workbooks to close once opened. This includes closing Excel. I have to kill the process in the task manager or in powershell to free the workbook from system memory.

Set fs = CreateObject("Scripting.FileSystemObject")
strExcelFileName = Dir(ThisWorkbook.Path & "\Certs\*.xls", vbNormal)
Set xlApp = CreateObject("Excel.Application")
Do While (strExcelFileName <> "")
      xlApp.Workbooks.Open (ThisWorkbook.Path & "\Certs\" + strExcelFileName)
      'code to run for each workbook opened
      ***xlApp.Workbooks.Close*** 'when present, Excel freezes
      strExcelFileName = Dir 'next file in directory
Loop

When the xlApp.Workbooks.Close line is present and called in the program, excel freezes every time. Without it, I can run through 3-5 workbooks before the system is overwhelmed and freezes. I then must kill those processes, move those files out, move 3 more in and repeat until all files have been processed this way. It takes about an hour and a half to go through 50.

What I am trying to do is have the workbook where the data is grabbed from closed before the next one is opened.

ActiveWorkbook.Close

This attempts to close the workbook where the macro is running, not the workbook that has been opened to be read from.

  • 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-01T12:48:59+00:00Added an answer on June 1, 2026 at 12:48 pm

    You already have Excel open so you do not need to open another copy. Try:

    Set WBookOther = Workbooks.Open(PathCrnt & FileNameCrnt)
      :
      :
    WBookOther.Close SaveChanges:=False
    

    This earlier answer of mine which cycles though every workbook in the current folder may help further.

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

Sidebar

Related Questions

I have written an Excel VBA macro which imports data from a HTML file
I have an Excel VBA Script I've written with help, I am not a
I have written a little Excel VBA report tool for my iPhone App sales.
I have written a simple ASP.NET MVC 2 application that stores data and can
I have an Outlook 2003 macro written in VBA. I would like to schedule
I have written some JavaScript that opens an element when an element is clicked.
I have two MS Office add-ins written in VBA that I would like to
I have currently written a sub, written in VBA, that is called by the
I have an Excel plug-in (written in C#) with a static variable that is
I have written a few modules of code in Access vba. Each code runs

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.