Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.crashesgpfs,microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Save to CSV macro crashes Excel 2003

Hi,

OK, forget about solving the crashing in Excel. But if you can assist with
the below design criteria that would be fantastic.

Regards,
Scott

"Scott Bass" <sas_l_739 at yahoo dot com dot au wrote in message
...
Hi,

Problem 0:

First of all, I'm not an Excel macro or VB programmer...

Problem 1:

Here is my design criteria:

* A workbook with 1 to n worksheets
* When the user saves the workbook, cycle thru all worksheets, saving them
to a CSV file in the same directory as the workbook
* Ideally, it would be great if I could detect whether the worksheet had
been modified and actually needed saving. I assume this would greatly
improve performance if I only changed one worksheet out of say 20.
* But it's critical that the CSV's be in sync with the worksheets, so
unconditionally saving of all worksheets is acceptable
* Then save the workbook itself in XLS format
* Return the user to the exact worksheet and cell he/she was editing
before the save
* I want the macro to override the normal save functionality (i.e. run if
the user clicks the save icon), as opposed to linking it to a specific
button added to the workbook.

From Googling the net plus some help from a colleague, here are my first
two attempts:

Version 1:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

On Error Resume Next

ThisBook = ThisWorkbook.Name
ThisPath = ThisWorkbook.Path

Application.DisplayAlerts = False
Application.EnableEvents = False

For Each Sheet In ThisWorkbook.Sheets
Sheet.Activate
ActiveSheet.SaveAs Filename:=ThisPath & "\" & ActiveSheet.Name,
FileFormat:=xlCSV _
, CreateBackup:=False
Next

ThisWorkbook.Sheets(1).Activate
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & ThisBook,
FileFormat:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=True

ThisWorkbook.Saved = True

Application.DisplayAlerts = True
Application.EnableEvents = True

Exit Sub

End Sub

Version 2:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

If SaveAsUI Then GoTo ExitHere

ThisBook = ThisWorkbook.Name
ThisPath = ThisWorkbook.Path

Application.DisplayAlerts = False
Application.EnableEvents = False

For Each Sheet In ThisWorkbook.Sheets
Sheet.Activate
ActiveSheet.SaveAs Filename:=ThisPath & "\" & ActiveSheet.Name,
FileFormat:=xlCSV _
, CreateBackup:=False
Next

ThisWorkbook.Sheets(1).Activate
ThisWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & ThisBook,
FileFormat:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False

ThisWorkbook.Saved = True

Application.DisplayAlerts = True
Application.EnableEvents = True


ExitHe
Exit Sub

End Sub

Neither of these totally meet the design criteria stated above, eg.
returning to the worksheet and cell the user was previously editing. Any
assistance meeting the above design criteria appreciated.

Problem 2:
Both of these macros crash Excel on my work machine, but not my home
machine. It also crashes Excel 2007 as tested by our helpdesk on another
machine. The Excel patch level on both my home and work machines is Excel
2003 (11.8211.8202) SP3.

There are of course differences between my work and home machine, but not
too onerous. I'm an administrator on my work machine, but there will be
some security settings that are different.

I know this is a tough question, but are there any known issues that would
cause the above macro to ***crash Excel*** (therefore it's a bug in Excel,
full stop)??? Or known issues that would cause Excel macros to crash in
general? Or, if you can be bothered to run this, does it crash on your
machine as well?

Thanks for any help you can offer.

Regards,
Scott



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
Excel 2007 crashes when perform SAVE AS to Excel 97-2003 Bagia Excel Discussion (Misc queries) 0 May 20th 09 04:21 AM
Print macro Excel 2003 used to work, now crashes Kate[_5_] Excel Programming 1 June 18th 08 07:34 PM
Macro misteriously crashes Excel 2007 - but not 2003 [email protected] Excel Programming 2 November 13th 07 01:15 PM
Network Macro Crashes (cannot Save 'read-only' File) Chuckles123[_120_] Excel Programming 0 May 12th 06 04:52 AM
Word 2003 Find/Change Automation from Excel 2003 crashes Excel 200 Joel Berry Excel Programming 9 March 6th 06 10:20 PM


All times are GMT +1. The time now is 10:02 PM.

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"