Microsoft KB Archive/97180

= Microsoft Knowledge Base =

FileDelete Macro Deletes File from Disk Within WinWord Session
Last reviewed: July 30, 1997

Article ID: Q97180

The information in this article applies to:


 * Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
 * Microsoft Word for Windows 95, versions 7.0, 7.0a
 * Microsoft Word 97 for Windows
 * Word for the Macintosh, versions 6.0, 6.0.1, 6.0.1a

SUMMARY
This article contains a FileDelete macro that deletes a file from any accessible drive within a Word for Windows or Word for the Macintosh session. You can use this macro as an alternative to choosing Find File from the File menu and then clicking the Delete button.

The FileDelete macro first determines whether the file exists. If the file exists, the macro deletes it. To ensure that the macro can locate program.

MORE INFORMATION
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code &quot;as is&quot; without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

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.

CAUTION: If you do not provide the full path, the macro deletes the file from the current directory.

CAUTION MACTINTOSH USERS: This macro does not move the specific file the Trash. The file will be permanently deleted.

The following is the text of the FileDelete macro:

Word97
Sub FileDelete

On Error Goto ErrHandler fil$ = InputBox$(&quot;Type file to delete and press Enter.&quot;) n = MsgBox(&quot;Are you sure you want to delete &quot; & fil$ & _  &quot;?&quot;, vbOKCancel+vbYesNo) If n = - 1 And fil$ <> &quot;&quot; Then Kill fil$ Exit Sub errhandler:

Msgbox Err.Description

End Sub

Word 2.0, 6.0, 7.0
Sub MAIN On Error Goto bye fil$ = InputBox$(&quot;Type file to delete and press Enter.&quot;) n = MsgBox(&quot;Are you sure you want to delete &quot; + fil$ + &quot;?&quot;, 3) If n = - 1 And fil$ <> &quot;&quot; Then Kill fil$ bye:

End Sub