Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Save Excel file
#3
Not Solved
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:
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.
Reply


Messages In This Thread
Save Excel file - by mv8167 - 07-13-2011, 12:57 AM
RE: Save Excel file - by rajpes - 07-13-2011, 09:20 AM
RE: Save Excel file - by mv8167 - 07-13-2011, 07:48 PM
RE: Save Excel file - by rajpes - 07-13-2011, 10:58 PM
RE: Save Excel file - by mv8167 - 07-14-2011, 02:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to export the output value of a webedit object to a new excel file. mounika6677 1 1,346 04-14-2019, 05:18 PM
Last Post: mounika6677
  Access not saved excel file randhirsinghskhn 0 942 09-04-2018, 07:26 AM
Last Post: randhirsinghskhn
  dtLocalSheet empty even though excel file contains data cantorre 2 2,248 05-10-2017, 12:47 PM
Last Post: vidhi
  Extract and save a file from zip folder using VB Script karthicksri07 1 6,210 06-29-2016, 02:19 PM
Last Post: Ankesh
  Unable to Save a file in UFT 12.0.2 (Sequence contains more than one matching elemen) noeldsouza89 0 2,493 02-02-2015, 03:03 PM
Last Post: noeldsouza89

Forum Jump:


Users browsing this thread: 1 Guest(s)