Micro Focus QTP (UFT) Forums
how to set relative path for excel - 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-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: how to set relative path for excel (/Thread-how-to-set-relative-path-for-excel)



how to set relative path for excel - kamalteja - 03-27-2008

Hi,

Below is my code:

Step 1:
Code:
Set objExcel = CreateObject("Excel.Application")
Step 2:
Code:
Set objWorkbook = objExcel.WorkBooks.Open("D:\Partner Security Program\Test_Data\InspectCustomer.xls")

Step 3:
Code:
Set objDriverSheet = objWorkbook.Worksheets("Inspect Customer")

In Step 2, I want to set the relative path like
Code:
Set objWorkbook = objExcel.WorkBooks.Open("..\ ..\Test_Data\InspectCustomer.xls")

It is prompting error saying it could not locate the file ... please let me know the exact syntax


RE: how to set relative path for excel - Cpt.Zack - 03-27-2008

What do you mean by a relative path.can you tell me your exact requirement.


RE: how to set relative path for excel - kamalteja - 03-28-2008

The test data in excel is stored in D:\Test_Data\Names.xls, if the script has to be run in a different system, where they do have D: drive, and they store the data in C: or any other Drive, the QTP should still be able to fetch the data.

How should I give the path so that data can be fetched from any drive, I tried with the following code, but QTP throws error stating that excel could not be located in the specified path

Code:
Set objWorkbook = objExcel.WorkBooks.Open("..\ ..\Test_Data\InspectCustomer.xls")



RE: how to set relative path for excel - Cpt.Zack - 03-28-2008

I dont have a direct method, but what you could try is, Write a code to search for a specific file and retrieve the address from this code.I am also a newbie,and I wish I could help you with a simpler solution. Please do tell me if you find one.


RE: how to set relative path for excel - Ian Walker - 06-28-2008

Kamalteja

If the file is on a LAN drive, just define the full path. That is, if I have two users, whose LAN drive \\glbfil04\groups\custchoice maps to G:\ for one user, and K:\ for the other, writing:
Code:
Set objWorkbook = objExcel.WorkBooks.Open("\\glbfil04groups\custchoice\Test_Data\InspectCustomer.xls")
will work, as long as the user has read access to the LAN and file.