Tuesday, February 15, 2011

Write in the Excel

strExcelPath = "C:\Documents and Settings\deepakpe\Desktop\Mine_doc\new.xlsx"

' Bind to Excel object.
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


'Delete the Excel
objexcel.Worksheets.Delete strExcelPath

' Create a new workbook.
objExcel.Workbooks.Add

' Bind to worksheet by creating an object
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
'objSheet.Name = "User Groups"

' Populate spreadsheet cells with user attributes.
objSheet.Cells(1, 1).Value = "User Common Name"
objSheet.Cells(2, 1).Value = "sAMAccountName"
objSheet.Cells(3, 1).Value = "Display Name"
objSheet.Cells(4, 1).Value = "Distinguished Name"
objSheet.Cells(5, 1).Value = "Groups"

' Enumerate groups and add group names to spreadsheet.
k = 5

objSheet.Range("A1:A4").Font.Bold = True
objSheet.Select
objSheet.Range("B5").Select
objExcel.ActiveWindow.FreezePanes = True
objExcel.Columns(1).ColumnWidth = 20
objExcel.Columns(2).ColumnWidth = 30
objexcel.Worksheets.Add
Set objSheet = objExcel.ActiveWorkbook.Worksheets(4)

Set objSheet = objExcel.ActiveWorkbook.Worksheets(2)
objSheet.Cells(1, 1).Value = "User Common Name"
objSheet.Cells(2, 1).Value = "sAMAccountName"
objSheet.Cells(3, 1).Value = "Display Name"
objSheet.Cells(4, 1).Value = "Distinguished Name"
objSheet.Cells(5, 1).Value = "Groups"

objSheet.Cells(1, 1).Value = "User Common Name"


' Save the spreadsheet and close the workbook.
' Specify Excel7 File Format.

objExcel.ActiveWorkbook.SaveAs strExcelPath
objExcel.ActiveWorkbook.Close

' Quit Excel.
objExcel.Application.Quit

' Clean Up  OR Realease the object
Set objUser = Nothing
Set objGroup = Nothing
Set objSheet = Nothing
Set objExcel = Nothing

Wscript.Echo "Done"

No comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | JCpenney Printable Coupons