LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default SaveAs Problem

Thank you Sharad, it works ! There is no end to man's ingenuity !
I had managed a workaround - shown below as a matter of interest.

Sub UserFileSave()
Dim Fname, Suggestion, Hdr
Suggestion = "MyFile " & Format(Date, "dd mmm yy")
Hdr = "Please choose a Location and Name then click Save."
On Error GoTo ERRH
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
Exit Sub
ERRH:
On Error Goto 0
MsgBox "Try another Name"
UserFileSave
End Sub

Thanks again and regards,
Don

"Sharad Naik" wrote in message
...
Try below code. Changes marked with '<-----

Sub UserFileSave()
Dim Fname, Suggestion, Hdr
Dim fs '<-------

Suggestion = "MyFile " & Format(Date, "dd mmm yy")
Hdr = "Please choose a Location and Name then click Save."

getFname: '<----- added label

Fname = Application.GetSaveAsFilename(Suggestion, fileFilter:="Excel File
(*.xls), *.xls)", Title:=Hdr)
If Fname = False Then
'Handle Cancel
UserCancel
Else
'<--------- new lines below
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists(Fname) Or fs.FlieExists(Fname & ".xls") Then
Select Case MsgBox ("File " & Fname & " already exists. " _
& "Do you want to replace it?" , vbYesNoCancel)
Case vbYes
On Error Resume Next
Kill Fname
Kill Fname & ".xls"
On Error GoTo 0
Case vbNo
GoTo getFname: 'get a new name then
Case vbCancel
Exit Sub 'used canceled
End Select
End If

ThisWorkbook.SaveAs FileName:=Fname
End If
End Sub

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

I've tried your code as is.
When the message saying that the file already exists shows and I choose
not to replace it, the error 1004 appears, which is fatal if not handled.

regards,
Don

"Norman Jones" wrote in message
...
Hi Don,

Revising your posted nacro to reflect my suggestion, gives:

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
ThisWorkbook.SaveAs Filename:=Fname
Else
' User Cancelled - dont save
End If
End Sub

This did not error for me.

---
Regards,
Norman



"Don Lloyd" wrote in message
...
Thank you Norman and Claud

Unfortunately neither method works properly as the error keeps coming
up when the offer to replace the file is declined.

For the time being I've managed to overcome it with "unqualified" error
trapping and then using recursion.

Thanks for your time and effort.

regards,
Don









 
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
Problem using SaveAs method Sujata Excel Discussion (Misc queries) 4 March 30th 10 07:21 AM
ActiveWorkbook.SaveAs Problem SowBelly Excel Programming 4 August 4th 04 10:58 PM
SaveAS w/ a variable name problem Jeffp Excel Programming 2 June 8th 04 12:51 PM
SaveAs problem Jessi Excel Programming 2 July 31st 03 07:36 PM
SaveAs problem, renames Worksheet too E.Anderegg Excel Programming 2 July 29th 03 02:54 AM


All times are GMT +1. The time now is 11:01 PM.

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"