Você está na página 1de 5

Microsoft Excel Scripts

Add Data to a Spreadsheet Cell


Add Formatted Data to a Spreadsheet
Create User Accounts Based on Information in a Spreadsheet
Format a Range of Cells
List Active Directory Data in a Spreadsheet
List Ecel Color !alues
List Service Data in a Spreadsheet
"pen an Ecel Spreadsheet
Read an Ecel Spreadsheet
Add Data to a Spreadsheet Cell
Demonstration script that adds the #ords $%est !alue$ to cell &'& in a ne# spreadsheet(
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(! ).Value = "Test "alue"
Add Formatted Data to a Spreadsheet
Demonstration script that adds the #ords $test value$ to a ne# spreadsheet' then formats the cell
containing the value(
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(! ).Value = "Test "alue"
objExcel.Cells(! ).#ont.$old = T%&E
objExcel.Cells(! ).#ont.Si'e = ()
objExcel.Cells(! ).#ont.Color*ndex = +
Create User Accounts Based on Information in a Spreadsheet
Demonstration script that creates ne# Active Directory user accounts )ased on information
stored in an Ecel spreadsheet(
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open ,
("C-.Scripts./e0,users.xls")
int%o0 = (
1o &ntil objExcel.Cells(int%o0!).Value = ""
Set objO& = 2etObject("ou=#inance! dc=3abrika4! dc=co4")
Set obj&ser = objO&.Create ,
("&ser"! "cn=" 5 objExcel.Cells(int%o0! ).Value)
obj&ser.sA6Account/a4e = objExcel.Cells(int%o0! ().Value
obj&ser.2i"en/a4e = objExcel.Cells(int%o0! +).Value
obj&ser.S/ = objExcel.Cells(int%o0! )).Value
obj&ser.Account1isabled = #A7SE
obj&ser.Set*n3o
int%o0 = int%o0 8
7oop
objExcel.9uit
Format a Range of Cells
Demonstration script that adds data to four different cells in a spreadsheet' then uses the Range
o)*ect to format multiple cells at the same time(
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(! ).Value = "/a4e"
objExcel.Cells(! ).#ont.$old = T%&E
objExcel.Cells(! ).*nterior.Color*ndex = +:
objExcel.Cells(! ).#ont.Color*ndex = (
objExcel.Cells((! ).Value = "Test "alue "
objExcel.Cells(+! ).Value = "Test "alue ("
objExcel.Cells()! ).Value = "Tets "alue +"
objExcel.Cells(;! ).Value = "Test "alue )"
Set obj%an<e = objExcel.%an<e("A"!"A;")
obj%an<e.#ont.Si'e = )
Set obj%an<e = objExcel.%an<e("A("!"A;")
obj%an<e.*nterior.Color*ndex = +=
Set obj%an<e = objExcel.Acti"eCell.EntireColu4n
obj%an<e.Auto#it()
List Actie Director! Data in a Spreadsheet
Demonstration script that retrieves data from Active Directory and then displays that data in an
Ecel spreadsheet(
Const A1S,SCO>E,S&$T%EE = (
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(! ).Value = "7ast na4e"
objExcel.Cells(! ().Value = "#irst na4e"
objExcel.Cells(! +).Value = "1epart4ent"
objExcel.Cells(! )).Value = ">?one nu4ber"
Set objConnection = CreateObject("A1O1$.Connection")
Set objCo44and = CreateObject("A1O1$.Co44and")
objConnection.>ro"ider = "A1s1SOObject"
objConnection.Open "Acti"e 1irector@ >ro"ider"
Set objCo44and.Acti"eConnection = objConnection
objCo44and.>roperties(">a<e Si'e") = ::
objCo44and.>roperties("Searc?scope") = A1S,SCO>E,S&$T%EE
objCo44and.Co44andText = ,
"SE7ECT <i"en/a4e! S/! depart4ent! telep?one/u4ber #%O6 " ,
5 "A71A>-BBdc=3abrika4!dc=4icroso3t!dc=co4A WCE%E " ,
5 "objectCate<or@=AuserA"
Set obj%ecordSet = objCo44and.Execute
obj%ecordSet.6o"e#irst
x = (
1o &ntil obj%ecordSet.EO#
objExcel.Cells(x! ).Value = ,
obj%ecordSet.#ields("S/").Value
objExcel.Cells(x! ().Value = ,
obj%ecordSet.#ields("<i"en/a4e").Value
objExcel.Cells(x! +).Value = ,
obj%ecordSet.#ields("depart4ent").Value
objExcel.Cells(x! )).Value = ,
obj%ecordSet.#ields("telep?one/u4ber").Value
x = x 8
obj%ecordSet.6o"e/ext
7oop
Set obj%an<e = objExcel.%an<e("A")
obj%an<e.Acti"ate
Set obj%an<e = objExcel.Acti"eCell.EntireColu4n
obj%an<e.Auto3it()
Set obj%an<e = objExcel.%an<e("$")
obj%an<e.Acti"ate
Set obj%an<e = objExcel.Acti"eCell.EntireColu4n
obj%an<e.Auto3it()
Set obj%an<e = objExcel.%an<e("C")
obj%an<e.Acti"ate
Set obj%an<e = objExcel.Acti"eCell.EntireColu4n
obj%an<e.Auto3it()
Set obj%an<e = objExcel.%an<e("1")
obj%an<e.Acti"ate
Set obj%an<e = objExcel.Acti"eCell.EntireColu4n
obj%an<e.Auto3it()
Set obj%an<e = objExcel.%an<e("A").SpecialCells()
Set obj%an<e( = objExcel.%an<e("C")
Set obj%an<e+ = objExcel.%an<e("A")
List Excel Color "alues
Demonstration script that displays the various colors ++ and their related color inde ++ availa)le
#hen programmatically controlling ,icrosoft Ecel(
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
#or i = to ;=
objExcel.Cells(i! ).Value = i
objExcel.Cells(i! ).*nterior.Color*ndex = i
/ext
List Serice Data in a Spreadsheet
Demonstration script that retrieves information a)out each service running on a computer' and
then displays that data in an Ecel spreadsheet(
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
x =
strCo4puter = "."
Set objW6*Ser"ice = 2etObject ,
("0in4<4ts-.." 5 strCo4puter 5 ".root.ci4"(")
Set colSer"ices = objW6*Ser"ice.Exec9uer@ ,
("Select D #ro4 Win+(,Ser"ice")
#or Eac? objSer"ice in colSer"ices
objExcel.Cells(x! ) = objSer"ice./a4e
objExcel.Cells(x! () = objSer"ice.State
x = x 8
/ext
#pen an Excel Spreadsheet
Demonstration script that opens an eisting Ecel spreadsheet named C-.Scripts./e#0users(ls(
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C-.Scripts./e0,users.xls")
Read an Excel Spreadsheet
Demonstration script that reads the values stored in a spreadsheet named
C-.Scripts./e#0users(ls(
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open ,
("C-.Scripts./e0,users.xls")
int%o0 = (
1o &ntil objExcel.Cells(int%o0!).Value = ""
Wscript.Ec?o "C/- " 5 objExcel.Cells(int%o0! ).Value
Wscript.Ec?o "sA6Account/a4e- " 5 objExcel.Cells(int%o0! ().Value
Wscript.Ec?o "2i"en/a4e- " 5 objExcel.Cells(int%o0! +).Value
Wscript.Ec?o "7ast/a4e- " 5 objExcel.Cells(int%o0! )).Value
int%o0 = int%o0 8
7oop
objExcel.9uit

Você também pode gostar