Excel

Workbook Name Minus the .xls

Ease of Use

Easy

Version tested with

2000, 2002 

Submitted by:

Justinlabenne

Description:

Udf''s that remove the .xls on ths end of your excel workbook names 

Discussion:

One way to use this function is as a normal worksheet function just like a formula. The FILENAMEIS2 function is best suited for this method. The other example is best used when called from a sub procedure, such as saving a copy of the workbook with the original filename and adding the date and time on the end. This makes it quicker and easier to just return the workbooks name for other uses. 

Code:

instructions for use

			

Option Explicit Function FILENAMEIS() As String ' Active wb's filename - .xls Application.Volatile True FILENAMEIS = Left$(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4) End Function Function FILENAMEIS2() As String ' From Zack Barresse ' Best option if using similiar to a formula in a cell Dim wbName As String Application.Volatile True wbName = Application.Caller.Parent.Parent.Name FILENAMEIS2 = Left(wbName, Len(wbName) - 4) End Function

How to use:

  1. Copy the above code.
  2. Open any workbook.
  3. Press (Alt + F11) to open the Visual Basic Editor (VBE).
  4. From the Menu, choose Insert-Module.
  5. Paste the code into the right-hand code window.
  6. Close the VBE (Alt + Q)
  7. Save the file if desired.
 

Test the code:

  1. Use it just llike a formula or call it from a sub-routine
  2. Either type it in a cell like: =FILENAMEIS2()
  3. and press enter
  4. or-
  5. Use the Paste-Function dialog
  6. It will be in the User-Defined category.
  7. or-
  8. Insert it into a sub-routine to be used within code
  9. Examples are included in the workbook
 

Sample File:

BookName.zip 9.28KB 

Approved by mdmackillop


This entry has been viewed 225 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express