Microsoft KB Archive/124336

= Microsoft Knowledge Base =

XL: Name Statement Does Not Recognize Wildcards
Last reviewed: March 27, 1997

Article ID: Q124336

5.00 5.00c 7.00 7.00a | 5.00 5.00a

WINDOWS   | MACINTOSH kbprg kbcode kbdocerr

The information in this article applies to:


 * Microsoft Excel for Windows 95, versions 7.0, 7.0a
 * Microsoft Excel for Windows, version 5.0,5.0c
 * Microsoft Excel for the Macintosh, versions 5.0, 5.0a

SYMPTOMS
In Microsoft Excel, Visual Basic Help states that the Name statement accepts wildcards. This information is incorrect: Name will not accept wildcards for either the oldpathname or the newpathname arguments.

If you rename a file using the Name statement, and you use the * or ? wildcards in the oldpathname or the newpathname arguments to match filenames, you will receive the following error message:

Run-Time Error '52' Bad Filename or number

WORKAROUND
To work around this problem, use the Dir function or the Kill statement (you can use wildcards with Dir and Kill) as they are used in the methods below.

Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

Method 1: Use the Dir function to find the files in the appropriate

directory, and then use the Name command to rename the file.

Sub FindandRename

'Find a matching file in the current directory that begins 'with "test" FindFile = Dir("test*.xls")

'Rename that found file to "testfile.xls" Name FindFile As "testfile.xls"

End Sub Method 2: Use the Kill statement to delete files, as in the following

example:

'This procedure deletes the file C:\NEWBK1.XLS Sub killtest KILL "C:\newbk?.xls" End Sub

STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post more information here in the Microsoft Knowledge Base as it becomes available.