Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Opening and closing many spreadsheets from .NET

Kyle,

it may seem obvious...
have you tried opening the files as read-only?

then he has no need to 'mark' the original


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"?B?S3lsZSBCYWxleQ==?="
wrote:

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).


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Opening and closing many spreadsheets from .NET

Sorry, should have specified. I'm opening the files read-only.

Other parameters:
- UpdateLinks: false
- WriteResPassword: false
- IgnoreReadOnlyRecommended: true
- Editable: false
- Notify: false
- AddToMru: false
- Local: false

All other parameters are set to System.Reflection.Missing.Value
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Opening and closing many spreadsheets from .NET


i'm sure you've disabled:

Application
.enableevents = false


BUT what are your settings for autorecover?
(it's played havoc on some of my apps)

.autorecover.enabled=false


either disable application.autorecover
or set the workbooks property after opening

Workbook.enableautorecover = false

else have a look at any other workbook properties that just might
slow you down...

sorry, that's it from me :-(



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"?B?S3lsZSBCYWxleQ==?="
wrote:

Sorry, should have specified. I'm opening the files read-only.

Other parameters:
- UpdateLinks: false
- WriteResPassword: false
- IgnoreReadOnlyRecommended: true
- Editable: false
- Notify: false
- AddToMru: false
- Local: false

All other parameters are set to System.Reflection.Missing.Value


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Opening and closing many spreadsheets from .NET

Good suggestions. I hadn't disabled events or auto-recover but it didn't help. Try some other options but they other made no difference or cause COM exceptions. Even tried setting ReadOnly to true but alas.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Opening and closing many spreadsheets from .NET

Good suggestions. I hadn't disabled events or autorecover but doing so didn't help. Tried some other options in the Open event and even tried setting ReadOnly to false but they other didn't work or caused COM exceptions.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Opening and closing many spreadsheets from .NET


including (some) doevents might work wonders.
(dont know the c equivalent, I'm just a simple VBA hack)


it will give either excel enough ticks to to complete calculations,
and you should allow some ticks to the OS to finish it's filehandling.

(dont know what your data entails :)

also make sure your temp directory is cleaned regularly....
no joke :(

depending on the contents of files (embedded ole objects/pictures) excel
can dump an awfull amount of data in temp... and certainly when developing
(and crashing).. it tends to leave 'some of these' files behind...


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"?B?S3lsZSBCYWxleQ==?="
wrote:

Good suggestions. I hadn't disabled events or autorecover but doing so
didn't help. Tried some other options in the Open event and even tried
setting ReadOnly to false but they other didn't work or caused COM
exceptions.


Reply
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 04:39 AM.

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"