adspace


How to store the iterations value in some variable/ in
excel?
Dim objExcel, ObjFolder, objPath, objWorkbook, objSheet,
ObjFSo, ObjFolderName, strExcelPath
Const xlExcel7 = 39

ObjFolderName = "Testing" & Hour(time()) & Minute(time())
&Second(time())
objPath = "D:\"
strExcelPath = objPath & ObjFolderName & "\testing.xls"
Set ObjFSo = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder(objPath & ObjFolderName)
On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Excel application not found."
Wscript.Quit
End If
On Error GoTo 0
Set objWorkbook = objExcel.Workbooks.Add()
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)


Dim arr1, arr2, arr3
Set outputLines = CreateObject
("System.Collections.ArrayList")
arr1 = 123arr2 = 99
arr3 = 10
outputLines.Add arr1
outputLines.Add arr2
outputLines.Add arr3
outputLines.Sort()
For Each outputLine in outputLines

WScript.Echo outputLine
' how to store this value in excel/ variable?

Next

objExcel.ActiveWorkbook.SaveAs strExcelPath, xlExcel7
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit

This above code is working fine but the qs is is there any
way to store the sort data in variables / in the excel and
how?

Answer Posted / Ankur Dixit

To store sorted data in a variable and then write it to an Excel file, you can modify your VBScript code as follows:

```vbscript
Dim arr1, arr2, arr3, outputArray
Set outputArray = CreateObject("System.Collections.ArrayList")
arr1 = 123
arr2 = 99
arr3 = 10
outputArray.Add arr1
outputArray.Add arr2
outputArray.Add arr3
outputArray.Sort

For Each outputLine in outputArray
WScript.Echo outputLine
Next

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Add
Set objSheet = objWorkbook.Worksheets(1)

Dim i, count
count = outputArray.Count
For i = 0 To count - 1
objSheet.Cells(i + 1, 1).Value = outputArray.Item(i)
Next
objExcel.ActiveWorkbook.SaveAs "D:Testingtesting.xls", xlExcel7
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
```

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

No New Questions to Answer in this Category !!    You can

Post New Questions

Answer Questions in Different Category