ATan
02-24-2009, 07:35 PM
I have this codes which help me to save 2 files, one as per the original filename and another with a date stamp. The codes will run fine as long as any of the file to be save is not opened. How can I change the codes to avoid this error. Preferably a message box to tell that the file is already opened and the macro will end.
Sub SaveFile()
Dim f As Variant
Dim strFileName As String
Dim strFileDirectory As String
Dim fname As String
fname = "ACR-WP8402"
strFileName = fname & " " & Format(Now(), "yyyy-mm-dd") & ".xls"
strFileDirectory = "I:\Final Cost Forecast-Infra\WP8402\"
'Show the SaveAs box
f = Application.GetSaveAsFilename(InitialFileName:=strFileDirectory & strFileName, _
FileFilter:="Microsoft Excel Workbook (*.xls),*.xls")
If f <> False Then
ActiveWorkbook.SaveAs strFileDirectory & strFileName
End If
ActiveWorkbook.SaveAs Filename:= _
"I:\Final Cost Forecast-Infra\WP8402\ACR-WP8402.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
End Sub
Sub SaveFile()
Dim f As Variant
Dim strFileName As String
Dim strFileDirectory As String
Dim fname As String
fname = "ACR-WP8402"
strFileName = fname & " " & Format(Now(), "yyyy-mm-dd") & ".xls"
strFileDirectory = "I:\Final Cost Forecast-Infra\WP8402\"
'Show the SaveAs box
f = Application.GetSaveAsFilename(InitialFileName:=strFileDirectory & strFileName, _
FileFilter:="Microsoft Excel Workbook (*.xls),*.xls")
If f <> False Then
ActiveWorkbook.SaveAs strFileDirectory & strFileName
End If
ActiveWorkbook.SaveAs Filename:= _
"I:\Final Cost Forecast-Infra\WP8402\ACR-WP8402.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
End Sub