kdjonesmtb2
Technical User
Hello,
The code below pulls data from an excel spreadsheet and writes it to text files
I need to be able to take each row of data from the spreadsheet and apply to a unique text file
The column data is used for each file but it file should represent a row of data in the excel spreadsheet
The follow code works but is tedious if I have to create 100 txt files
How can I automate the loop to pull the unique cell values from each row of data and and create the txt files?
Dim objexcel
Dim objWorkbook
Dim objDriverSheet
Dim intRow
Dim File_Header_REF7
Dim REF01_Reference_Identification_Qualifier4
Dim REF02_Reference_Identification5
Dim File_Header_REF7_1
Dim REF01_Reference_Identification_Qualifier4_1
Dim REF02_Reference_Identification5_1
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 intRow = 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))
print "File_Header_REF7"
Print File_Header_REF7
Print "REF01_Reference_Identification_Qualifier4 "
Print REF01_Reference_Identification_Qualifier4
print "REF02_Reference_Identification5"
print REF02_Reference_Identification5
'Next
Introw=3
'For intRow = 3 to objDriverSheet.UsedRange.Rows.Count
File_Header_REF7_1 = Trim(objDriverSheet.Range("A"& intRow ))
REF01_Reference_Identification_Qualifier4_1 = Trim(objDriverSheet.Range("B"& intRow))
REF02_Reference_Identification5_1 =Trim(objDriverSheet.Range("C" & intRow))
print "File_Header_REF7_1"
Print File_Header_REF7_1
Print "REF01_Reference_Identification_Qualifier4_1 "
Print REF01_Reference_Identification_Qualifier4_1
print "REF02_Reference_Identification5_1"
print REF02_Reference_Identification5_1
'Next
'Set QTPfile = FSO.OpenTextFile("c:\myfile.txt", ForAppending, True)
If textfilename = "qtptest2.x12" then
qfile1.Close
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set fso=createobject("Scripting.FileSystemObject")
Set qfile1 = fspenTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP 834\Text files\qtptest2.x12", ForAppending,True)
qfile1.Write(File_Header_REF7)
qfile1.Write((DataTable.Value("Common_Delimiter",dtLocalSheet)))
qfile1.Write(REF01_Reference_Identification_Qualifier4)
qfile1.Write((DataTable.Value("Common_Delimiter",dtLocalSheet)))
qfile1.Write(REF02_Reference_Identification5)
qfile1.Write((DataTable.Value("Tilde",dtLocalSheet))) & vbcrlf
qfile1.close
End if
qfile1.Close
If textfilename = "qtptest3.x12" then
Set qfile1 = fspenTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP 834\Text files\qtptest3.x12", ForAppending,True)
qfile1.Write(File_Header_REF7_1)
qfile1.Write((DataTable.Value("Common_Delimiter",dtLocalSheet)))
qfile1.Write(REF01_Reference_Identification_Qualifier4_1)
qfile1.Write((DataTable.Value("Common_Delimiter",dtLocalSheet)))
qfile1.Write(REF02_Reference_Identification5_1)
qfile1.Write((DataTable.Value("Tilde",dtLocalSheet))) & vbcrlf
qfile1.Close
End if
The code below pulls data from an excel spreadsheet and writes it to text files
I need to be able to take each row of data from the spreadsheet and apply to a unique text file
The column data is used for each file but it file should represent a row of data in the excel spreadsheet
The follow code works but is tedious if I have to create 100 txt files
How can I automate the loop to pull the unique cell values from each row of data and and create the txt files?
Dim objexcel
Dim objWorkbook
Dim objDriverSheet
Dim intRow
Dim File_Header_REF7
Dim REF01_Reference_Identification_Qualifier4
Dim REF02_Reference_Identification5
Dim File_Header_REF7_1
Dim REF01_Reference_Identification_Qualifier4_1
Dim REF02_Reference_Identification5_1
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 intRow = 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))
print "File_Header_REF7"
Print File_Header_REF7
Print "REF01_Reference_Identification_Qualifier4 "
Print REF01_Reference_Identification_Qualifier4
print "REF02_Reference_Identification5"
print REF02_Reference_Identification5
'Next
Introw=3
'For intRow = 3 to objDriverSheet.UsedRange.Rows.Count
File_Header_REF7_1 = Trim(objDriverSheet.Range("A"& intRow ))
REF01_Reference_Identification_Qualifier4_1 = Trim(objDriverSheet.Range("B"& intRow))
REF02_Reference_Identification5_1 =Trim(objDriverSheet.Range("C" & intRow))
print "File_Header_REF7_1"
Print File_Header_REF7_1
Print "REF01_Reference_Identification_Qualifier4_1 "
Print REF01_Reference_Identification_Qualifier4_1
print "REF02_Reference_Identification5_1"
print REF02_Reference_Identification5_1
'Next
'Set QTPfile = FSO.OpenTextFile("c:\myfile.txt", ForAppending, True)
If textfilename = "qtptest2.x12" then
qfile1.Close
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set fso=createobject("Scripting.FileSystemObject")
Set qfile1 = fspenTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP 834\Text files\qtptest2.x12", ForAppending,True)
qfile1.Write(File_Header_REF7)
qfile1.Write((DataTable.Value("Common_Delimiter",dtLocalSheet)))
qfile1.Write(REF01_Reference_Identification_Qualifier4)
qfile1.Write((DataTable.Value("Common_Delimiter",dtLocalSheet)))
qfile1.Write(REF02_Reference_Identification5)
qfile1.Write((DataTable.Value("Tilde",dtLocalSheet))) & vbcrlf
qfile1.close
End if
qfile1.Close
If textfilename = "qtptest3.x12" then
Set qfile1 = fspenTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP 834\Text files\qtptest3.x12", ForAppending,True)
qfile1.Write(File_Header_REF7_1)
qfile1.Write((DataTable.Value("Common_Delimiter",dtLocalSheet)))
qfile1.Write(REF01_Reference_Identification_Qualifier4_1)
qfile1.Write((DataTable.Value("Common_Delimiter",dtLocalSheet)))
qfile1.Write(REF02_Reference_Identification5_1)
qfile1.Write((DataTable.Value("Tilde",dtLocalSheet))) & vbcrlf
qfile1.Close
End if