Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to set relative path for excel
#1
Solved: 10 Years, 9 Months, 3 Weeks ago
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
Reply
#2
Solved: 10 Years, 9 Months, 3 Weeks ago
What do you mean by a relative path.can you tell me your exact requirement.
Reply
#3
Solved: 10 Years, 9 Months, 3 Weeks ago
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")
Reply
#4
Solved: 10 Years, 9 Months, 3 Weeks ago
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.
Reply
#5
Solved: 10 Years, 9 Months, 3 Weeks ago
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to get relative path by using testdir environment variable Sathyaprasad 1 1,795 11-30-2017, 02:21 AM
Last Post: supputuri
  Want to read the data from excel and set read value in the JavaTable rajeevk7 0 2,174 07-10-2017, 04:20 PM
Last Post: rajeevk7
  Path of Flight reservation Window is not recorded in HP UFT 12.52 version mailtokopalverma@gmail.com 1 2,414 04-01-2016, 05:34 PM
Last Post: vinod123
  X path Identification vasavi.vasavi 1 2,710 07-29-2015, 10:44 AM
Last Post: kbhargava505
  environment variable path for qc automation2012 0 2,641 01-18-2015, 08:18 AM
Last Post: automation2012

Forum Jump:


Users browsing this thread: 2 Guest(s)