Microsoft KB Archive/169093
Article ID: 169093
Article Last Modified on 1/19/2007
- Microsoft Office 97 Standard Edition
- Microsoft Excel 97 Standard Edition
- Microsoft Word 97 Standard Edition
- Microsoft Access 97 Standard Edition
- Microsoft PowerPoint 97 Standard Edition
This article was previously published under Q169093
In any of the programs listed at the beginning of this article, if you run a Visual Basic for Applications macro that includes the Kill statement, the macro may delete all of the files stored in a folder on a network server.
This behavior may occur when all of the following conditions are true:
- A drive letter is mapped to a folder on a network server. -and-
- The network server is running Microsoft Windows NT Server, version 3.51 or 4.0, or Microsoft Windows NT Workstation, version 3.51 or 4.0. -and-
- The current directory is the root directory of the mapped network drive. -and-
You use syntax for the Kill statement that is similar to either of the following
where <FileList> is a variable that refers to nothing (""), a variable that is uninitialized, or a variable that refers to a path that does not include a file name.
If all of the above conditions are true, all of the files in the root directory of the mapped network drive may be deleted without warning.
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 professionals 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.
To prevent files from being deleted by the Kill statement, verify that the Kill statements always refer to both a valid path and a valid file name. The following examples demonstrate the syntax to use:
Dim FileList As String FileList = "*.old" Kill "\\server\share\myfiles\" & FileList
Dim FileList As String, NetPath As String NetPath = "\\server\share\myfiles\" FileList = "*.old" Kill NetPath & FileList
These are all valid uses of the Kill statement.
You can also prevent this problem from occurring by making sure that there are no drive letters that are mapped to shares on the network server. The problem occurs only if a drive letter is mapped to the server.
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 new information here in the Microsoft Knowledge Base as it becomes available.
The Kill statement in Visual Basic for Applications allows you to delete files from a disk. The syntax is as follows:
The variable <pathname> refers to the path and file name of the file (or files) that you want to delete. You can use multiple character (*) and single character (?) wildcards to specify multiple files that you want to delete with the Kill statement.
If you want to delete all of the files in a folder, make sure that the path name that is used by the Kill statement ends in "*.*." For example, to delete all of the files in the folder E:\myfiles, you could use the following code:
Dim FileList As String FileList = "*.*" Kill "E:\myfiles\" & FileList
Do NOT use a path name without a valid file name. For example, the following Kill statements may cause the problem described in this article to occur:
Kill "" Kill "\\server\share\" Kill "\\server\share\myfiles\" Kill "E:\" Kill "E:\myfiles\" Dim FileList As String Kill FileList Dim FileList As String Kill "\\server\share\myfiles\" & FileList
If the current folder or the folder that is specified in the Kill statement is stored on a computer running Microsoft Windows 95, or if the folder is stored on a computer running Microsoft Windows NT, and no drive letter is mapped to the server, you receive the following error message
if the path name is invalid. In this case, no files are deleted.
For more information about the Kill statement, click the Office Assistant in the Visual Basic Editor, type kill, click Search, and then click to view "Kill Statement."
NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Microsoft Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:
120802 Office: How to Add/Remove a Single Office Program or Component
Additional query words: XL97 xlvbainfo
Keywords: kbbug kbprogramming KB169093