RobertPaulsen
Wed Mar 15 14:50:29 CST 2006
You can also try "Environ("username")". The function is part of the VBA
library, so your project should already have a reference to it.
"Karl E. Peterson" wrote:
> Q wrote:
> > I have a word document with some code behind it.
> > In the code, I want to know the user who is logged on to
> > the machine.
> > Can this be done from within VBA in a word document?
>
> Absolutely...
>
> Private Declare Function GetUserName Lib "advapi32.dll" Alias
> "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
> Private Const UNLEN As Long = 256 ' Maximum username length
>
> Private Function CurrentUserName() As String
> Dim Buffer As String
> Dim nLen As Long
> Const NameLength = UNLEN + 1
>
> Buffer = Space$(NameLength)
> nLen = Len(Buffer)
> If GetUserName(Buffer, nLen) Then
> CurrentUserName = Left$(Buffer, nLen - 1)
> End If
> End Function
>
> Later... Karl
> --
> Working without a .NET?
>
http://classicvb.org/
>
>
>