setting custom footer in This Workbook that opens everytime (default template)

  • Thread starter Thread starter Pablo
  • Start date Start date
P

Pablo

Hello:

I'd like to have a default template that everytime it's open has code
in the This Workbook.

The code I have sets a custom footer with the username and I want this
to be attached to the workbook so when I e-mail the file, the new
users will have the same functionality.

I made a workbook called "Book1.xlt" and saved it in my XLStart folder
with the custom footer code in the This Workbook, but when I restarted
XL the code was not in my new workbook.
 
Private Sub Workbook_BeforePrint(Cacel As Boolean)
With ActiveWorkbook
.ActiveSheet.PageSetup.LeftFooter = "User: " & UserName
End With
End Sub

This goes in the ThisWorkbok code module.

In a standard code module, add

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

Function UserName() As String
Dim S As String
Dim L As Long
Dim R As Long
S = String$(255, " ")
L = Len(S)
R = GetUserName(S, L)
UserName = Left(S, L - 1)
End Function

--

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