View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default File Save, yes, no, cancel macro

nuver,
One way...
'-------------
Function IsItSafe()
'Jim Cone - San Francisco, USA - Nov 07, 2005
'Requires a project reference to "Microsoft Scripting Runtime" library

Dim objFSO As Scripting.FileSystemObject
Dim sName As String
Dim strPath As String
Dim sPath As String
Dim sh As Excel.Worksheet
sPath = ActiveWorkbook.Path
Set objFSO = New Scripting.FileSystemObject
For Each sh In ActiveWorkbook.Worksheets
strPath = sPath & "\" & "Master " & sh.Name & ".xls"
If Not objFSO.FileExists(strPath) Then
sh.Copy
ActiveWorkbook.SaveAs sPath & "\" & "Master " & sh.Name & ".xls", xlNormal
Else
sName = InputBox(sh.Name & " already exists. " & vbCr & _
"Enter the new file name", "Sheet Save")
sh.Copy
ActiveWorkbook.SaveAs sPath & "\" & sName & ".xls", xlNormal
End If
Next
Set objFSO = Nothing
Set sh = Nothing
End Function
'----------------------


"nuver" wrote in message...
Hello
With a macro I need to close my file and save the file as the sheet
name in the current directory. I can accomplish this with the code
below, but if the file exists and the user selects no to the replace
existing file prompt then, I need to prompt the user to enter a new
name to save the file as under the same directory. Once the new name is
entered I need the macro to continue.

Any help is greatly appreciated.

Dim sPath As String
Dim sh As Worksheet
sPath = ActiveWorkbook.Path
For Each sh In ActiveWorkbook.Worksheets
sh.Copy
ActiveWorkbook.SaveAs sPath & "\" & "Master " & sh.Name & _
".xls", xlNormal
Next
nuver