File name in the footer/header

B

Basharat A. Javaid

Is there a way to insert the file name in a footer/header without the ".xls"
in the name?


Basharat.
 
G

Gary''s Student

Put the following in the Workbook event mcro area:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
ActiveSheet.PageSetup.CenterHeader = ActiveWorkbook.Name
End Sub
 
D

Dave Peterson

And to remove the last 4 characters of the .name:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
dim myName as string
myName = me.name
worksheets("Somesheetnamehere").PageSetup.CenterHeader _
= right(myname,len(myname)-4)
End Sub

I used the Me keyword--it refers to the object that owns the code. In this
case, it's the workbook that's being printed.

And I only changed a specific worksheet--not the activesheet.
 

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