Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default deleting worksheets corrupts files

I have various modules which open several workbooks (one by one), make
changes, then save & close them. Whenever I run a module in which
sheets are deleted via...

Application.DisplayAlerts = False
Worksheets(strMySheet).Delete
Application.DisplayAlerts = True

the file becomes corrupt. It saves and closes ok, but when trying to
open the file later, Excel crashes, giving the message:

Excel has caused an error in EXCEL.EXE. Excel will now close.

I've tried code cleaner, and even pasting the code into notepad, then
back into a new module, but neither has worked. I'm having to open the
files using OpenOffice, then saving in a different format then
re-opening with Excel. But I'm working with over a few hundred files
so I don't really have time to do this.

I'm not positive it's the sheet deletion that does it, but I've pretty
much narrowed it down to that because it's common among all the problem
mods and absent from all the others. Has anyone ever had trouble with
deleting sheets / file corruption? Anyone have any suggestions?
Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 718
Default deleting worksheets corrupts files

Hi

I came across the same problem this morning. My macro saves a copy of my
'master' workbook and then turns it into a report to send out, (doing things
like copy-paste values, delete sheets, etc.). As you described, the files
save, and close fine, but then Excel 2000 crashes when I try to re-open.

However, Excel 2002 is able to open the offending files. I've been into
one, and gone into the VBE. in the project explorer pane, I can see the
problem. Under the subfolder "Microsoft Excel Objects" are the two sheets I
intended to be there, and a "ThisWorkbook" module. Bizzarrely though, there
is also one of the sheets that my macro deleted ("Data"), and the icon next
to it is like that of "Thisworkbook".

Presumably, Excel 2000 sees two "ThisWorkbook" type modules and doesn't know
which one is real. Excel 2002 copes.

What I don't know is why the "Data" sheet in particular was not deleted
properly. The line of code making sheet deletions used an array of sheet
names:
sheets(array("sht1","sht2","data","sht4")).delete

Any help much appreciated
Thanks
Rob




People using Office 2002 were able to open the file

" wrote:

I have various modules which open several workbooks (one by one), make
changes, then save & close them. Whenever I run a module in which
sheets are deleted via...

Application.DisplayAlerts = False
Worksheets(strMySheet).Delete
Application.DisplayAlerts = True

the file becomes corrupt. It saves and closes ok, but when trying to
open the file later, Excel crashes, giving the message:

Excel has caused an error in EXCEL.EXE. Excel will now close.

I've tried code cleaner, and even pasting the code into notepad, then
back into a new module, but neither has worked. I'm having to open the
files using OpenOffice, then saving in a different format then
re-opening with Excel. But I'm working with over a few hundred files
so I don't really have time to do this.

I'm not positive it's the sheet deletion that does it, but I've pretty
much narrowed it down to that because it's common among all the problem
mods and absent from all the others. Has anyone ever had trouble with
deleting sheets / file corruption? Anyone have any suggestions?
Thanks.


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
Deleting Files Ben Dover New Users to Excel 2 August 4th 07 04:03 PM
File corrupts when saving under a different name - xl2000 Clayman Excel Discussion (Misc queries) 8 June 18th 07 07:19 PM
Reference to DLL corrupts on recompile of dll Robin Hammond[_2_] Excel Programming 2 April 12th 04 08:49 AM
Deleting files Tony C[_2_] Excel Programming 1 February 17th 04 12:27 PM
Deleting Files From VBA Brett[_4_] Excel Programming 3 November 21st 03 11:10 PM


All times are GMT +1. The time now is 02:21 AM.

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

About Us

"It's about Microsoft Excel"