Knet59
02-01-2008, 03:47 AM
With the code below i will get a VB error with yellow highligt on "ActiveWorkbook.SaveAs Filename:=file_name" when the file exists and i pick No or Cancel to replace it.
What is wrong or missing?
Private Sub CmdSpara_Click()
' Save as
Dim file_name As Variant
Dim FName As String
FName = Sheets("Sheet 1").Range("A1").Value & ".xls"
' Get the file name.
file_name = Application.GetSaveAsFilename(FName, _
FileFilter:="Excel Files,*.xls,All Files,*.*", _
Title:="Save As File Name")
' See if the user canceled.
If file_name = False Then Exit Sub
' Save the file with the new name.
If LCase$(Right$(file_name, 4)) <> ".xls" Then
file_name = file_name & ".xls"
End If
ActiveWorkbook.SaveAs Filename:=file_name
End Sub
What is wrong or missing?
Private Sub CmdSpara_Click()
' Save as
Dim file_name As Variant
Dim FName As String
FName = Sheets("Sheet 1").Range("A1").Value & ".xls"
' Get the file name.
file_name = Application.GetSaveAsFilename(FName, _
FileFilter:="Excel Files,*.xls,All Files,*.*", _
Title:="Save As File Name")
' See if the user canceled.
If file_name = False Then Exit Sub
' Save the file with the new name.
If LCase$(Right$(file_name, 4)) <> ".xls" Then
file_name = file_name & ".xls"
End If
ActiveWorkbook.SaveAs Filename:=file_name
End Sub