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: 22
Default Error trap only works once

Hello :-)

I have some code to save a workbook for the first time using the SaveAs
dialog.

I need to trap if the same filename is currently being used by aother Excel
session -to prevent VBA from getting upset.

Essentially the code is:

Dim FD As FileDialog ' Variable for dialog object

On Error GoTo ErrorHandler

'Create file dialog object
Set FD = Application.FileDialog(MsoFileDialogType.msoFileDi alogSaveAs)

'Set the default file name (& path)
FD.InitialFileName = Application.DefaultFilePath & "\Planning Spreadsheet"

SaveLoop: 'Point to restart save routine if error occurred
'Display the save as dialog and save file if cancel not selected
If FD.Show < 0 Then FD.Execute
On Error GoTo 0
Exit Sub

ErrorHandler:
' Traps file save error e.g. if file currently in use by another Excel session
MsgBox "Please change the file name", vbExclamation, "File Currently In
Use"
On Error GoTo ErrorHandler
GoTo SaveLoop ' Return to Save As dialog
End Sub

The error trap works fine the first time round, however if I try to
overwrite the file a second time I get a run time error 2147467259 (80004005)
Cannot Access Planning Spreadsheet.xls

I have also tried Err.Clear.

How can I reset the error handler? If I hide and reshow the SaveAs dialog,
would this clear it? If so, how do I hide the built in dialog as it doesn't
seem to have a Hide method?

Regards and thanks,

Z
 
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
Need error trap GregR Excel Programming 4 June 14th 07 08:28 PM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
Error Trap Kirk P. Excel Programming 2 September 8th 05 09:51 PM
error trap Rhonda[_3_] Excel Programming 2 October 22nd 03 07:07 PM


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