Micro Focus QTP (UFT) Forums
how to find Excel file exist or not in vbscript code - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/forum-3.html)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/forum-6.html)
+--- Thread: how to find Excel file exist or not in vbscript code (/thread-6680.html)



how to find Excel file exist or not in vbscript code - sree.85 - 08-13-2012

How can I find whether Microsoft Excel file exists or not using VB Script code in UFT/QTP? 
It will be great if I can get a working script.


RE: how to find Excel file exist or not in vbscript code - Veera0383 - 08-21-2013

Hi,

Below code might help you...
Code:
set objFSO = createobject("Scripting.FileSystemObject") objFSO.FileExists("C:\FileFolder\Filename.xls")

Veera

For checking File not exists you can use the below

Code:
If not objFSO.FileExists("C:\FileFolder\Filename.xls") then Your Action... End if



RE: how to find Excel file exist or not in vbscript code - akhandesh - 08-22-2013

This is a function library i have written for retrieving the data from an excel sheet.
But whenever i tried to execute the same code i get General Run Error.
can anybody suggest me the right answer.



Code:
Function FindObject(ObjectName) Set desc=description.Create For j=1 to datatable.GetSheet("OR1").GetRowCount datatable.GetSheet("OR1").SetCurrentRow(j) If datatable("name","OR1")=ObjectName Then If datatable("micclass","OR1")<>" " Then desc("micclass").value=datatable("micclass","OR1") End If ' If datatable("html id","OR1")<>" " Then ' desc("micclass").value=datatable("html id","OR1") ' End If If datatable("class","OR1")<>" " Then desc("micclass").value=datatable("class","OR1") End If If datatable("innertext","OR1")<>" " Then desc("micclass").value=datatable("innertext","OR1") End If Set obj=Browser("creationtime:=0").page("title:=.*").ChildObjects(desc) FindObject=obj(0) 'obj1=FindObject(obj) End If Next End Function

General Run Error

Function file:
C:\Program Files\HP\QuickTest Professional\Tests\FindObject.vbs
Line (29): " FindObject=obj(0)"


this is the Error i get whenever i execute the Above code


How to Debug the General Run Error : - akhandesh - 08-22-2013

Hi,

I am getting the below error : when i execute the below code that i have written in Function library.

General Run Error
Function file: C:\Program Files\HP\QuickTest Pro


Code:
Function FindObject(ObjectName) Set desc=description.Create For j=1 to datatable.GetSheet("OR1").GetRowCount datatable.GetSheet("OR1").SetCurrentRow(j) If datatable("name","OR1")=ObjectName Then If datatable("micclass","OR1")<>" " Then desc("micclass").value=datatable("micclass","OR1") End If ' If datatable("html id","OR1")<>" " Then ' desc("micclass").value=datatable("html id","OR1") ' End If If datatable("class","OR1")<>" " Then desc("micclass").value=datatable("class","OR1") End If If datatable("innertext","OR1")<>" " Then desc("micclass").value=datatable("innertext","OR1") End If Set obj=Browser("creationtime:=0").page("title:=.*").ChildObjects(desc) FindObject=obj(0) 'obj1=FindObject(obj) End If Next End Function