USER

  • Thread starter Thread starter Fernando Duran
  • Start date Start date
F

Fernando Duran

hI, DO WE HAVE A FUNCTION OR VARIABLE THAT WE CAN USE TO PRINT THE
USER NAME IN THE NETWORK IN THE FOOTER OR THE HEADER?

THANKS IN ADVANCE
 
Hi Fernando
you can process the workbook_beforprint event. Put the following code
in your workbook module:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim wkSht As Worksheet
For Each wkSht In ActiveWindow.SelectedSheets
With wkSht.PageSetup
.CenterFooter = "User-Name: " & Application.UserName
End With
Next wkSht
End Sub

This will put the user name into the center footer section for all
selected worksheets.
HTH
Frank
P.S.: please turn off your CAPS lock. Your text is difficult to read
and considered rude (shouting) in newsgroups
 
Sorry Frank, I just use all day capital letters or most of the day.
I tryed your code, it works, but it doest pick-up the user name in the
network, seems to be using something from Excel.
Fernando
 
Fernando,

Network user is not part of Excel, but it can be retrieved with APIs. Try
this

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

Public Function UserName() As String
Dim sName As String * 256
Dim cChars As Long
cChars = 256
If GetUserName(sName, cChars) Then
UserName = Left$(sName, cChars - 1)
End If
End Function

This code goes in a standard code module.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
ActiveSheet.PageSetup.LeftFooter = UserName
End Sub

This code goes in Thisworkbook code module.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Fernando

For a single worksheet........

Sub NameInFooter()
ActiveSheet.PageSetup.RightFooter = Application.UserName
End Sub

For all worksheets in workbook..............

Sub Name_All_Sheets()
Set wkbktodo = ActiveWorkbook
For Each ws In wkbktodo.Worksheets
ws.PageSetup.RightFooter = Application.UserName
Next
End Sub

Gord Dibben Excel MVP
 
Gord,

He had already stated that it was the network user name he was after.

Bob
 
Thanks Bob.

Wasn't paying attention, I guess. Lot of that going around at my desk.

Gord
 
Thanks guys, I just plug the code as Bob instruct me... I have to test
it, I was a little busy all day.
 
Back
Top