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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Creating a VBScript File

Status
Not open for further replies.

RDSpider

IS-IT--Management
May 21, 2008
3
AU
Hi,

I currently have a list of servers and I am trying to create a VBscript to do the following via Excel:

a. reads all the items in the named range
b. queries AD and determines the domain of the server
c. places the name of the domain of the server in the cell adjacent to it.
d. Place a command button on sheet
e. Attach the script to the button
f. Click the button!

Been a long time since I have made anything like this, so I really need a refresh. Thanks guys.
 
What do you have so far?

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
At this stage not a lot really...

Currently I believe all I have done with this script is grab the data from the cells in excel and I am storing them in an array.

Set objXL = CreateObject("Excel.Application")
Set objWB = objXL.WorkBooks.Open("G:\FeSG\ITSB\Architecture\Working - Shane Weir\applan.xls")
Set objWS = objXL.ActiveWorkBook.WorkSheets("sheet1")

Dim CellArray()
ACount = 0
For i = 1 To 30
If objXL.Cells(i, 9).Value = "" Then
CellValue = "Empty"
Else
CellValue = objXL.Cells(i, 9).Value
End If

ReDim preserve CellArray(ACount)
CellArray(ACount) = CellValue
ACount = ACount + 1
Next
objWB.Close
objXL.Quit
 
I don't fully understand your approach at this so here is my suggestion to get you started.

Code:
On Error Resume Next

Set objXL = CreateObject("Excel.Application")
Set objWB = objXL.WorkBooks.Open("G:\FeSG\ITSB\Architecture\Working - Shane Weir\applan.xls")
Set objWS = objXL.ActiveWorkBook.WorkSheets("sheet1")

xlRow = 1
Do Until Len(xlRow,9) = ""
    strComputer = objXL.Cells(i, 9).Value
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	Set colItems = objWMIService.ExecQuery("Select * from Win32_NTDomain",,48)
	For Each objItem in colItems
		If InStr(UCase(objItem.Name),UCase(strComputer)) = False Then
[green]    		'Now we fill in a cell (column 10) with the domain information[/green]
    		objXL.Cells(i, 10).Value = Replace(objItem.Name, "Domain: ","") 
    	End If
[green]        'Put the rest of your worker code in here.[/green]
	Next   
    XLRow = XLRow + 1
Loop
objWB.Close
objXL.Quit

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Correction to the above:

Do Until Len(objXL.cells(xlRow,9).value) = 0

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top