UserName Function: Not Working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I used this little trick in the office for a few recent projects:
http://www.j-walk.com/ss/excel/tips/tip94.htm

It works perfectly fine on the machines in the office, with the exception of
one machine. As far as I can tell, we have all the MS critical updates for
this machine. I found the advapi32.dll on the problem-machine too. I can't
figure out what it is. Any thoughts or suggestions?

Regards,
Ryan--
 
Hi,
What do you mean by it doesn't work:
- returns the wrong username
- an error pops up
- ...
 
What error message?
We're not clairvoyant, you see........

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

| Oh yes, sorry, an error message pops up.
| Any thoughts on what may cause this?
|
| --
| RyGuy
|
|
| "sebastienm" wrote:
|
| > Hi,
| > What do you mean by it doesn't work:
| > - returns the wrong username
| > - an error pops up
| > - ...
| > --
| > Regards,
| > Sébastien
| > <http://www.ondemandanalysis.com>
| >
| >
| > "ryguy7272" wrote:
| >
| > > I used this little trick in the office for a few recent projects:
| > > http://www.j-walk.com/ss/excel/tips/tip94.htm
| > >
| > > It works perfectly fine on the machines in the office, with the exception of
| > > one machine. As far as I can tell, we have all the MS critical updates for
| > > this machine. I found the advapi32.dll on the problem-machine too. I can't
| > > figure out what it is. Any thoughts or suggestions?
| > >
| > > Regards,
| > > Ryan--
| > >
| > >
| > > --
| > > RyGuy
 
What error message?

In the meantime, you may want to try this implementation, found on vbcode.com:

Public Function GetLoggedInUserName() as string
Dim cn As String
dim Name as String
Dim ls As Long
Dim res As Long

cn = String(1024, 0)
ls = 1024
res = GetUserName(cn, ls)

If res <> 0 Then
name = Mid(cn, 1, InStr(cn, Chr(0)) - 1)
Else
name = ""
End If

GetLoggedInUserName = Name
End function
 
Whoops, sorry again.; very tired now. I think the error says:
#NAME

I'm not at that workstation to test it now.

I was thinking it may be a corrupt dll file. Is that possible? Could the
'advapi32.dll' gotten corrupted and caused JWalk's function to create this
error? Doesn't XP just rebuild these types of corrupted dll files? I've
been using VBA for a couple of years and I haven't run into this before. I'm
baffled. Any insight would be appreciated.
 
Thanks for taking a crack at it everyone. Still unsure what the problem is,
but I am going to use a different technique altogether.


Regards,
Ryan--
 
Back
Top