View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Hawkide Hawkide is offline
external usenet poster
 
Posts: 6
Default System info in header/footer.

If you want to return the user name that the user has registered with the
application you can use:

ActiveUserName = Application.UserNameInsert

---------------------------------------------------------------------------------
To return the network user name use:

Public Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function ReturnUserName() As String
' returns the NT Domain User Name
Dim rString As String * 255, sLen As Long, tString As String
tString = ""
On Error Resume Next
sLen = GetUserName(rString, 255)
sLen = InStr(1, rString, Chr(0))
If sLen 0 Then
tString = Left(rString, sLen - 1)
Else
tString = rString
End If
On Error GoTo 0
ReturnUserName = UCase(Trim(tString))
End Function

---------------------------------------------------------------------------------
To return the computer name use:

Private Declare Function GetComputerName Lib "kernel32" _
Alias "GetComputerNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long


Function ReturnComputerName() As String
Dim rString As String * 255, sLen As Long, tString As String
tString = ""
On Error Resume Next
sLen = GetComputerName(rString, 255)
sLen = InStr(1, rString, Chr(0))
If sLen 0 Then
tString = Left(rString, sLen - 1)
Else
tString = rString
End If
On Error GoTo 0
ReturnComputerName = UCase(Trim(tString))
End Function

---------------------------------------------------------------------------------
You can then use the two functions to create your footer

ActiveSheet.PageSetup.LeftFooter = ReturnComputerName
ActiveSheet.PageSetup.RightFooter = ReturnUserNam
---------------------------------------------------------------------------------

"Josh" wrote:

How can I reference system information, i.e. user name, computer name, and
other system info, to put them into the header and footer?
I would like to put the user name and computer name in the footer, for
document tracking purposes.