Print the user name

  • Thread starter Thread starter Adrian Hernandez
  • Start date Start date
A

Adrian Hernandez

I want to know if there is a function to
put in the header or footer a leyend like this
"Printed by: " and then a function to print the
user name who is printing the document.

I recall something similar in a previous version
of Excel ( 95 or 97) that has it.

Thanks..
 
Hi Adrian,

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)
 

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

Back
Top