Working With Other Workbooks And Files

Exir

You can only use the Kill statement to remove files; it does not remove folders. To delete a folder you can use the RmDir statement. The only argument for the RmDir statement—the path argument — is not required. If you attempt to omit the argument, VBA tries to delete the current folder. The path argument consists of a string containing the path specifying the folder location to remove. For example, the code RmDir("c:\Excel Files") removes the folder on the specified path. The RmDir statement only removes folders; it does not remove any files. If the folder you are deleting contains any files, an error message displays warning you that Excel cannot remove the folder.

When working with folders, you may need to know the current path in order to determine which folder to remove, or whether the folder exists. You can determine the current folder using the CurDir function. The CurDir function returns a string containing the path for the current folder. Typically, you can assign the value returned by the function to a variable, as shown in the code CurrentFolder

Example:

-Q Type Kill(DeleteWb).

S Switch to Excel and run the macro.

■ Excel removes the specified files from your computer.

-Q Type Kill(DeleteWb).

S Switch to Excel and run the macro.

■ Excel removes the specified files from your computer.

0 0

Post a comment