Re: VB Script help

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



VB is not the same as VBScript, and you
actually need someone who uses VBScript
*and* Excel. I don't know about any Excel
groups, but there's a VBS group here:

microsoft.public.scripting.vbscript


Bellow you will find script I am using to extract name and emails from
distibution lists we have, but as it is now I have to type group name
and OU name.. how would I search AD for and figure out OU. So I do not
need to type it in?

Thank you

'/*** SCRIPT START ***/

Dim objGroup, objExcel, iRow, strUser, strGroup, strOU

'Get group name
strGroup = InputBox("Please type full groupname as you see it on MS
Outlook: ")
strOU = InputBox("Please type OU group belongs to; ")

Set objGroup = GetObject("LDAP://CN="; & strGroup & ",OU=GROUPS, OU=" &
strOU & ",DC=mydomain,DC=net")

Set objExcel = CreateObject("Excel.Application")

With objExcel
.SheetsInNewWorkbook = 1
.Workbooks.Add
.Visible = True
irow=2
.Cells(1,1) = "Name"
.Cells(1,2) = "E-mail Address"
.cells(1,5) = "Here is list of users along with their e-mail
addresses" & strGroup
For Each strUser in objGroup.Member

Set objUser = GetObject("LDAP://"; & strUser)
.Cells(iRow,1) = objUser.CN
.Cells(iRow,2) = objUser.mail
irow=irow + 1

Next
.rows(1).select
.Selection.Font.Bold = True
.rows(2).select
.ActiveWindow.FreezePanes = True
.cells(2,1).select
.Columns(1).entirecolumn.autofit
.Columns(2).entirecolumn.autofit

End With


Set objExcel = Nothing
Set objGroup = Nothing

'/*** SCRIPT END ***/



.


Quantcast