Thread: SaveAs Problem
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default SaveAs Problem

Hi Don,

Try:

If Fname < False Then
ThisWorkbook.SaveAs Filename:=Fname
Else
' User Cancelled - don't save
End If

---
Regards,
Norman



"Don Lloyd" wrote in message
...
Hi All,

Happy New Year - belated but well meant :)

I'm programmatically using the SaveAs Dialog Box to allow the user to
decide where to save a file.

If the chosen path already exists, SaveAs points this out.
Fine, except that, if the option to not overwrite the file is chosen, an
error 1004 message appears. Clicking Help helpfully displays a blank Help
screen.

In short, how do I handle this error. Code example as follows.

Sub UserFileSave()
Dim Fname, Suggestion, Hdr
Suggestion = "MyFile " & Format(Date, "dd mmm yy")
Hdr = "Please choose a Location and Name then click Save."
Fname = Application.GetSaveAsFilename(Suggestion, fileFilter:="Excel File
(*.xls), *.xls)", Title:=Hdr)
If Fname = False Then
'Handle Cancel
UserCancel
Else
ThisWorkbook.SaveAs FileName:=Fname
End If
End Sub

Regards,
Don
( XL97 Win98 / XL2003 WinXp )