Office Programing help

R

Ramkee

Hi could some one help me on this.

My requirement is as follows:

I would like to place a button / radio button on a xls document and once
the user clicks on the button, I would like to capture the user's windows
login id / machine name on a column separate column on the same work sheet.

Your help is much appreciated.
Thanks
 
K

Karl E. Peterson

Ramkee said:
I would like to place a button / radio button on a xls document and once
the user clicks on the button, I would like to capture the user's windows
login id / machine name on a column separate column on the same work sheet.

Here's the code to call, indented to highlight wordwrap, once you get the button
push:

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
(ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA"
(ByVal lpBuffer As String, nSize As Long) As Long

Private Const UNLEN As Long = 256 ' Maximum username length
Private Const CNLEN As Long = 15 ' Maximum computer name length

Public Function CurrentMachineName() As String
Dim Buffer As String
Dim nLen As Long
Const NameLength = CNLEN + 1
Buffer = Space$(NameLength)
nLen = Len(Buffer)
If GetComputerName(Buffer, nLen) Then
CurrentMachineName = Left$(Buffer, nLen)
End If
End Function

Public 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top