USER

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
 
F

Frank Kabel

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
 
F

Fernando Duran

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
 
B

Bob Phillips

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)
 
G

Gord Dibben

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
 
B

Bob Phillips

Gord,

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

Bob
 
G

Gord Dibben

Thanks Bob.

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

Gord
 
F

Fernando Duran

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

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