LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Opening and closing many spreadsheets from .NET

This is a question about working with Excel from .NET so if this is the wrong newsgroup, please let me know. Technologies are .NET Framework 1.1, C#, Excel 2003.

I have a Windows Forms app that is extracting information from about 450 similarly formatted spreadsheets. So I'm opening the spreadsheet, extracting the info into a dataset, closing the spreadsheet and moving on to the next one.

I always get an error when opening some spreadsheets. It's not the spreadsheets because it fails on different ones each time through. E.g. It will fail on the twelfth one the first time, then the twenty-third one the next time, and so on.

It's not a .NET error (so I can't trap it in a try-catch block). When it fails, a dialog appears with Microsoft Visual Basic as the title (I'm using C#) and the message is "File already exists". Note that I have Interactive set to false for the Excel application.

My theory is that I'm opening and closing spreadsheets too fast because when I put a Thread.Sleep(100) between the Close/Open statements, it works (although much slower than I'd like). I suspect that Excel is creating a temporary file based on the current time when the spreadsheet is opened and isn't deleting it fast enough when it is closed. So when the next spreadsheet is opened in the same "time frame" it tries to create a new temp file with the same name.

One final note: If I don't reference the Worksheets collection of the workbook, no error occurs. It fails only when I starting working with the sheets in the workbook (even if all I do is set a variable to workbook.Worksheets.Count).
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Slow Opening & Odd Closing ohsix New Users to Excel 1 May 20th 07 05:28 PM
Closing a workbook upon opening another Dave New Users to Excel 3 January 3rd 07 09:57 PM
Opening and closing workbook with VBA... Trevor[_4_] Excel Programming 1 March 4th 04 08:33 PM
Opening and Closing workbooks Jase Excel Programming 1 October 15th 03 06:28 AM
Opening and closing text files Vince[_3_] Excel Programming 1 August 11th 03 09:43 PM


All times are GMT +1. The time now is 11:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"