Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Receiving Unknown runtime error in script - Need to be able to use Excel file to load var or array

Status
Not open for further replies.

kdjonesmtb2

Technical User
Nov 19, 2012
93
US


I am using an Excel file to load variables in the vbscript code below

I do not think that I have the script set up correctly to load an array that would represent all the columns and rows in the Excel file:

The Excel file layout and values are below:

I am receiving the following error when I run the script:

Unknown runtime error

Line (3587): "File_Header_REF7 = Trim(objDriverSheet.Range("A"& intRow))".

Dim objexcel
Dim objWorkbook
Dim objDriverSheet
Dim intStartRow
Dim File_Header_REF7
Dim REF01_Reference_Identification_Qualifier4
Dim REF02_Reference_Identification5

set objexcel = Createobject("Excel.Application")
'xlApp.visible = true
Set objWorkbook = objexcel.WorkBooks.Open("M:\QTP 834\DataTable_Spillover.xls")
Set objDriverSheet = objWorkbook.Worksheets("Sheet1")
intStartRow = 2
For intStartRow = 2 to objDriverSheet.UsedRange.Rows.Count
File_Header_REF7 = Trim(objDriverSheet.Range("A"& intRow))
REF01_Reference_Identification_Qualifier4 = Trim(objDriverSheet.Range("A"& intRow))
REF02_Reference_Identification5 =Trim(objDriverSheet.Range("C" & intRow))


Next




Excel file being used in script

File_Header_REF7; REF01_Reference_Identification_Qualifier4; REF02_Reference_Identification5
REF 0F 999999900
REF 0F 999999900
REF 0F 999999900
 
Do yourself a favor: use the Option Explicit statement ...
Anyway, replace this:
For intStartRow = 2
with this:
For intRow = 2

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hello

Thanks the change worked

However, I still need to assign unique variable names to each element in the Excel table

How can I update the code below to assign unique variable name to each cell in the Excel table?

Dim objexcel
Dim objWorkbook
Dim objDriverSheet
Dim intRow
Dim File_Header_REF7
Dim REF01_Reference_Identification_Qualifier4
Dim REF02_Reference_Identification5

set objexcel = Createobject("Excel.Application")
'xlApp.visible = true
Set objWorkbook = objexcel.WorkBooks.Open("M:\QTP 834\DataTable_Spillover.xls")
Set objDriverSheet = objWorkbook.Worksheets("Sheet1")
intRow = 2
For inttRow = 2 to objDriverSheet.UsedRange.Rows.Count
File_Header_REF7 = Trim(objDriverSheet.Range("A"& intRow))
REF01_Reference_Identification_Qualifier4 = Trim(objDriverSheet.Range("B"& intRow))
REF02_Reference_Identification5 =Trim(objDriverSheet.Range("C" & intRow))


Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top