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.
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.