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

* Ideally, it would be great if I could detect whether the worksheet had
been modified and actually needed saving.

I didn't do anything with this but it can (and should) be done.

* Then save the workbook itself in XLS format

Since you're using the beforesave workbook event, the workbook will be
saved in it's present format after the procedure runs.

* Return the user to the exact worksheet and cell he/she was editing before
the save

The active sheet/cell won't change, so no return is necessary.

Option Explicit

Private Sub Workbook_BeforeSave _
(ByVal SaveAsUI As Boolean, Cancel As Boolean)
On Error GoTo errHandler

Dim ThisPath As String
Dim Sheet As Worksheet
Dim FileName As String

With Application
.DisplayAlerts = False
.EnableEvents = False
.ScreenUpdating = False
End With

For Each Sheet In Sheets 'since you're _
in the workbook module, no workbook _
reference is required when referring _
to this workbook

ThisPath = Path 'same here

FileName = ThisPath & "\" & Sheet.Name & ".csv"

Sheet.Copy
With ActiveWorkbook
.SaveAs FileName:=FileName, FileFormat:=xlCSVMSDOS
.Close 'I took the liberty of closing _
the newly created csv files
End With
Next

Cleanup:
With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = False
End With

Exit Sub

errHandler:
MsgBox Err.Source & " " & _
Err.Number & " " & _
Err.Description
GoTo Cleanup
End Sub

Cliff Edwards
 
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
Save to CSV macro crashes Excel 2003 Scott Bass Excel Programming 0 June 22nd 08 03:38 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


All times are GMT +1. The time now is 10:30 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"