07-13-2011, 07:48 PM
Rajpes,
Thx for sticking this out with me.
I thought that objExcel.ActiveWorkbooks.Save would work because it seemned that this objExcel.ActiveWorkBook.SaveAs (FilePath) worked. Now Im not sure.
I tried using the code that you had supplied last week on another thread but it also did not work. But the Excel file I have is already open. So, I dont think I need to open/crete (unless there is a reason to do so). In another Function I check if the Excel ss has been created or not. Here I just want to check, If my open Excel ss is not exist, used SaveAs. If it exsists, then Save.
I know I am missunderstanding something. Do I even need to use Save or SaveAs? All I want to do is save my open Excel file. Do I need to even check if it Exists or not?
So far I have tried all of the ways I can figure out, each in turn getting errors.
My Open Function works fine:
My Save/SafeAs Function does not work so well. (This code comes from an online source)
Code:
Error:
Object doesn't support this property or method: 'objExcel.saveas'
Function file: O:\QTP Tests\LibraryImageAccessFunctions-2.qfl
Line (1041): " objExcel.saveas FilePath 'Use the SaveAs method if the file has never been saved before".
Where can I go within QTP to read what methods are allowed for objects, etc?
Thx for helping me better understan this.
Thx for sticking this out with me.
I thought that objExcel.ActiveWorkbooks.Save would work because it seemned that this objExcel.ActiveWorkBook.SaveAs (FilePath) worked. Now Im not sure.
I tried using the code that you had supplied last week on another thread but it also did not work. But the Excel file I have is already open. So, I dont think I need to open/crete (unless there is a reason to do so). In another Function I check if the Excel ss has been created or not. Here I just want to check, If my open Excel ss is not exist, used SaveAs. If it exsists, then Save.
I know I am missunderstanding something. Do I even need to use Save or SaveAs? All I want to do is save my open Excel file. Do I need to even check if it Exists or not?
So far I have tried all of the ways I can figure out, each in turn getting errors.
My Open Function works fine:
Code:
Public Function OpenClearOrCreateExcelSheet (FilePath, objExcel)
Set objFso = CreateObject("Scripting.FileSystemObject")
'Check if file already Exists
bFileExist = objFso.FileExists(sSourceFile)
If bFileExist Then ' If the File exists open it
objExcel.Workbooks.Open (sSourceFile)
objExcel.Visible = True
'Clear DataSheet
objExcel.ActiveWorkbook.Sheets("sheet1").UsedRange.Rows.ClearContents
Else ' If the File does not exist, then Create a new file
objExcel.Workbooks.Add
End If
objExcel.Visible = True
Set oSheet = objExcel.Activesheet
'Set oSheet = objExcel.ActiveWorkBook.WorkSheets(Sheet1)
Set Cells = oSheet.Cells
objExcel.DisplayAlerts = False
End Function
My Save/SafeAs Function does not work so well. (This code comes from an online source)
Code:
Error:
Object doesn't support this property or method: 'objExcel.saveas'
Function file: O:\QTP Tests\LibraryImageAccessFunctions-2.qfl
Line (1041): " objExcel.saveas FilePath 'Use the SaveAs method if the file has never been saved before".
Where can I go within QTP to read what methods are allowed for objects, etc?
Thx for helping me better understan this.