Forum Discussion
aredev
Jun 04, 2018Copper Contributor
Remove File Extension in Custom Header in an Excel Sheet
When I insert file name as using &[File] in the custom header, the file extension ".xlsx " also gets added & printed. How can I display & print an Excel sheet without file extension?
Jun 05, 2018
Hello,
what you describe can only be done with VBA. You need to add this code to the ThisWorkbook module:
Private Sub Workbook_BeforePrint(Cancel As Boolean) ActiveSheet.PageSetup.CenterHeader = UCase(Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5)) End Sub
- aredevJun 05, 2018Copper Contributor
Hello Ingeborg, Thanks
Can I use this code for all types of workbooks, be it .xlsx or .xltx? Do I need to save the workbook as .xlsm, i.e as macro-enabled workbook? If so, how can use .xlsm workbook as a template?
- Jun 05, 2018
Hello,
if you use this approach, the workbook must be saved as a macro-enabled workbook, i.e. with either the .xlsm or .xlsb file extension.
You can create a template that contains this macro by saving the file as a macro-enabled template with the .xltm extension.
- aredevJun 06, 2018Copper ContributorThanks a ton! I'll connect back if I need any further assistance. Cheers! :D