Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default System info in header/footer.

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default System info in header/footer.

Here is some code to put in ThisWorkbook module

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim sText As String
With ActiveSheet.PageSetup
sText = "User: " & CreateObject("Wscript.Network").UserName & _
", Computer: " &
CreateObject("Wscript.Network").ComputerName
.LeftFooter = sText
End With
End Sub

--

HTH

RP

"Josh" wrote in message
...
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.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default System info in header/footer.

Shouldn't

ActiveUserName = Application.UserNameInsert

be

ActiveUserName = Application.UserName


And why6 doi you upshift the computer name and user name in those functions?

--

HTH

RP


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default System info in header/footer.

Is there a listing of attributes in those libraries that I can reference?

"Hawkide" wrote:

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 = ReturnUserName
---------------------------------------------------------------------------------

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 691
Default System info in header/footer.

Hi Josh,
Basically for headers and footers, I would think you would be interested in
Description VBA code Example
Full Name: Application.ActiveWorkbook.FullName D:\TestFolder\test.xls
Sheetname: application.activesheet.name Sheet1
More information in
Pathname in headings, footers, and cells
http://www.mvps.org/dmcritchie/excel/pathname.htm

But from the question you asked about other computer information:
Properties
http://www.mvps.org/dmcritchie/excel/property.htm
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

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



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default System info in header/footer.

Oops...Yes it should be:

ActiveUserName = Application.UserName

Not quite sure what you mean by upshift the names???

"Bob Phillips" wrote:

Shouldn't

ActiveUserName = Application.UserNameInsert

be

ActiveUserName = Application.UserName


And why6 doi you upshift the computer name and user name in those functions?

--

HTH

RP



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default System info in header/footer.

Sorry Josh, I am not sure how to get a "list of attributes" for a .dll file.
You may want ot check the MS website. If you want info on the functions, you
can peruse the API functions at:

http://msdn.microsoft.com/library/de...ical_order.asp

"Josh" wrote:

Is there a listing of attributes in those libraries that I can reference?

"Hawkide" wrote:

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 = ReturnUserName
---------------------------------------------------------------------------------

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

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default System info in header/footer.

Josh, if you don't like the uppercase names, just change:

UCase(Trim(tString))

to:

Trim(tString)


"Josh" wrote:

Is there a listing of attributes in those libraries that I can reference?

"Hawkide" wrote:

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 = ReturnUserName
---------------------------------------------------------------------------------

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

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default System info in header/footer.

Ohhhh, you must mean the uppercase function. There is no need to use the
"UCase" function. This is a copy from previous code, and I must have needed
it for a strcmp or something. I guess I should look a little more closely
before posting old code. I hope I didn't cause Josh any confusion...

I'll post a note to Josh...

"Bob Phillips" wrote:

Shouldn't

ActiveUserName = Application.UserNameInsert

be

ActiveUserName = Application.UserName


And why6 doi you upshift the computer name and user name in those functions?

--

HTH

RP



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Header & Footer Info w/ Worksheet Option Buttons Ryan H Excel Discussion (Misc queries) 0 December 8th 09 03:09 PM
Format header/footer info? L.S. Excel Discussion (Misc queries) 2 October 30th 09 07:25 PM
Extended System Info Dallman Ross Excel Discussion (Misc queries) 13 September 18th 06 12:53 AM
How to copy header/footer info? Capt'n Roy Excel Programming 2 October 14th 03 02:37 PM
extract info from XP File System Raad Excel Programming 0 September 30th 03 07:50 PM


All times are GMT +1. The time now is 07:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"