Vbscript write output to excel doing multiple rows

Asked By 50 points N/A Posted on -

Hey guys,

I am collecting WMI information for a few different remote hosts. I want to export the Vbscript write output to Excel spreadsheet. I want each piece pf WMI that I retrieve from each computer to be written on a separate row. It should look something like:

row 1 – name/serial number/make/model
row 2 – name/serial number/make/model


Answered By 0 points N/A #176606

Vbscript write output to excel doing multiple rows


If you want to extract data from excel following VB script will be needful.

Dim objExcel

Dim excelPath

Dim worksheetCount
Dim counter

Dim currentWorkSheet

Dim usedColumnsCount

Dim usedRowsCount
Dim row
Dim column

Dim top

Dim Cells

Dim curCol
Dim curRow

Dim word

excelPath = "C:ExcelFilesBook2.xls"

WScript.Echo "Reading Data from " & excelPath

Set objExcel = CreateObject("Excel.Application")

objExcel.DisplayAlerts = 0

objExcel.Workbooks.open excelPath, false, true

workSheetCount = objExcel.Worksheets.Count

WScript.Echo "We have " & workSheetCount & " worksheets"

For counter = 1 to workSheetCount
	WScript.Echo "-----------------------------------------------"
	WScript.Echo "Reading data from worksheet " & counter & vbCRLF

	Set currentWorkSheet = objExcel.ActiveWorkbook.Worksheets(counter)
	usedColumnsCount = currentWorkSheet.UsedRange.Columns.Count
	usedRowsCount = currentWorkSheet.UsedRange.Rows.Count

	top = currentWorksheet.UsedRange.Row
	left = currentWorksheet.UsedRange.Column

	Set Cells = currentWorksheet.Cells
	For row = 0 to (usedRowsCount-1)
		For column = 0 to usedColumnsCount-1
			curRow = row+top
			curCol = column+left
			word = Cells(curRow,curCol).Value
			WScript.Echo (word)

	Set currentWorkSheet = Nothing


Set currentWorkSheet = Nothing

Set objExcel = Nothing




Login/Register to Answer

Related Questions