Custom header - File name w/o extension?

Y

Y.

Is there a way in the custom headers to print the filename
without the extension?

So I want "Filename"
not "Filename.xls"

If I use VBA, and put a sub on the worksheet open to print
the header like this

Private Sub Workbook_Open()

ActiveSheet.PageSetup.LeftHeader = "&F"

End Sub


I would just need to delete the last four characters (.xls)
How do I do this in VBA?
 
D

Dave Smith

ActiveSheet.PageSetup.LeftHeader = Left(ThisWorkbook.Name,
InStr(ThisWorkbook.Name, ".") - 1)

This assumes that the name has a "." in it. If it might not (as it probably
won't before it is saved for the first time), try something like this

ActiveSheet.PageSetup.LeftHeader = IIf(InStr(ThisWorkbook.Name, ".") = 0,
ThisWorkbook.Name, Left(ThisWorkbook.Name, InStr(ThisWorkbook.Name, ".") -
1))

-Dave
 
D

Dave Peterson

How about just dropping the last 4 characters of the name:

Option Explicit
Private Sub Workbook_Open()
ActiveSheet.PageSetup.LeftHeader = Left(Me.Name, Len(Me.Name) - 4)
End Sub

Since this is behind the ThisWorkbook module, the "Me" refers to the workbook
that is being opened.
 

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