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

How to display the names for the given user IDs?

Status
Not open for further replies.

Ankor

Programmer
Mar 21, 2002
144
US
Hello all!
I have an Excel spreadsheet with the list of NT user IDs. They all are from different domains. I need to write the code that will display the user name in another cell. I know how to do that if I write something like this:
Sub FindName()
Dim Path
Dim objUserInfo
Dim UserInfo
Dim n
For n = 1 To 1000
User = Range("A" & n).Value
Select Case Left(User, 3)
Case "AAA", "AAB", "AAC", "AAD", "AAE"
Domain = "NTMAIN"
Case "BBB", "BBC"
Domain = "NTR1"
Case ..................
.......................
End Select
Path = "WinNT://" & Domain & "/" & User
Set objUserInfo = GetObject(Path)
UserInfo = objUserInfo.FullName
Range("B" & n).Value = UserInfo
Next
If IsObject(objUserInfo) Then Set objUserInfo = Nothing
End Sub


The problem here is that I don't want to write a hundred of cases in order to detemnine the domain name. Is there any way I can pass the user ID into some kind of script and it will return the domain?

Thank you in advance.
 
Create a collection of objects that has user names and domains as properties and search through the collection.

Use the user name (or the first three letters) as the key and then see if the key returns an object.

Here's the search code...

Private function SearchForKey(byval colCollection as collection, byval strKey as string) as boolean
dim objObject as object

on error Goto Err_SearchForKey
set objobject=colcollection(strkey)
searchforkey=true
set objobject=nothing


Exit_SearchForKey:
exit function

Err_SearchForKey:
searchforkey=false
resume exit_searchforkey

end function

Here's the class module code
public strUser as string
public strDomain as string

'of course you should consider using private variables and property procedures.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top