07-07-2011, 11:01 PM
What is wrong with
My code:
Code:
objExcel.ActiveWorkbook.SaveAs (FilePath)
My code:
Code:
Public Function SaveOrSaveAsAndCloseExcelSheet (FilePath, objExcel)
'USE to Save or Save As and then Close an Excel sheet
sSourceFile = FilePath
Set objFso = CreateObject("Scripting.FileSystemObject")
'Check if file already Exists
bFileExist = objFso.FileExists(sSourceFile)
If bFileExist Then 'Save - Use the Save method as the file has never been saved
objExcel.Workbooks.Save '(FilePath)
Else 'Save As - Use the SaveA s method as the file has been saved
objExcel.Workbooks.SaveAs (FilePath)
End If
objExcel.Visible = False
objExcel.DisplayAlerts = False
objExcel.Quit
Set objExcel=Nothing
Set objFso=Nothing
objExcel.Workbooks.Close()
End Function