|
Output the Name of the Current Excel Workbook Without the File Extension - UDF
Free Excel UDF that displays the name of the Excel workbook without its extension. This is a great UDF (user defined function) to use when you want to display the name of your workbook but don't want to have to also display the workbook file extension .xls .xlsm etc.
This UDF is simple to use as it requires no arguments or user-supplied data; just enter it into your spreadsheet and you're done.
Where to install the macro: Module
UDF to Output the Name of the Current Excel Workbook Without the File Extension
Function NAMEWORKBOOK() As String
NAMEWORKBOOK = Left(ThisWorkbook.Name, InStr(1, ThisWorkbook.Name, ".", vbTextCompare) - 1)
End Function
How to Install the Macro
- Select and copy the text from within the grey box above.
- Open the Microsoft Excel file in which you would like the Macro to function.
- Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.
Or For other ways to get there, Click Here.
For Excel Versions Prior to Excel 2007 Go to Tools > Macros > Visual Basic Editor
For Excel 2007 Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic
- On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.
- If the Macro goes in a Module, Click Here, otherwise continue to Step 8.
- Go to the menu at the top of the window and click Insert > Module
- Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
- Go to Step 8.
- If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Go to Step 8.
- If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
- Go to Step 8.
- Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.
- You are now ready to run the macro.
Similar Helpful Excel Resources
I have a few files sent out to field users. These users, for some reason, really love to change my .xlsm excel files to .xlsx when they save. Is there any VBA code that will help with this? The closest I could come up with is using the BeforeSave workbook event, but this still allows the user to make any changes they want to extension once the Save As dialog box appears.
Example of what I want:
User clicks save as, types in a new file name and selects .xls
Macro assigns the previous file extension to the file then saves it.
Sub Macro1()
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "COOPtbl1", "C:\Documents and Settings\kanegr\My Documents\Book1.xls", True, ""
End Sub
Heres the code I keep getting a
"Run-time error '424':
Object required"
Message.
I'm trying to effectively create an 'attachment' button like you might find in a hotmail email account, so that there's a quick, simple way for people to inserrt any file into the workbook. I've tried recording a macro following the Insert/Object/Create from File route but only end up with a visual basic string for inserting a particular file, which I've been unsuccessful in altering to get where I want. Any bright ideas?
I recently changed my HD in my desktop and upgraded the OS from Windows XP Home edition to Windows Vista ultimate. I'm able to open all programns that I was running before except excel. I'm getting the error message "Excel 2007 excel cannot open the file because the file format or file extension is not valid". I have tried to follow suggested solutions posted in the forum but non is conclusive. Please help...anybody...
I'm trying to create a macro to save multiple sheets of data as separate text files but i cannot have the .txt file extension. Any ideas?
I have a MS Excel 2003 file that has xml in it but a .xls file extension.
When I open it up in MS Excel 2003 it opens with no problem.
However, if I open the file in MS Excel 2007 it first shows a dialog mentioning the file is in a different format then specified by the file extension. Is there a way to avoid getting that dialog in 2007 since 2003 never displayed the dialog?
Also, I noticed that if I change the file extension to .xml it opens in MS Excel 2007 with no dialog. However, we prefer to keep the file extension as .xls.
Thanks,
Patrick
I received a file with an extension snp, is there any way I can convert or
import to MS Excel format?
Thanks.
Is there a way to find the file extension using VBA ie .xls or .xlam etc when the option to hide known file extensions has been selected.
I need something along the lines of
VB:
If file extension Is .xls Then
Code
ElseIf file extension Is .xlam Then
Code
Endif
If you like these VB formatting tags please consider sponsoring me in support of injured Royal Marines
thank you
Ian
Dear all,
Good day!
May I know whether it is possible to keep an .xml extension file inside Excel so that I can update .xml file when I run the macro?
I need to send an .xml file to our customers to update monthly but sometimes they will do it wrongly. So I really hope if I can keep that .xml file inside macro and update it at hard core location at C:\Program Files\XX\ExportAccess\
Many many thanks in advance for all the help
Hi, i need help in creating a macro that will inport file exention which has WK4 , i have lotus notes at work i have exported email file to drive U:\ , i require a macro to pick this file up and export to Sheet Group_Mailbox. The range is A9
|
|