How to Specify a File Path with the VBA Kill Statement in WPS Spreadsheets
Question details
The user needs to specify a reliable file path when using the VBA Kill statement in WPS Spreadsheets so the target file is deleted from the intended folder, not from an unpredictable current directory.

- Product
- WPS Spreadsheets
- Device & OS
- not provided
- Scenario
- A user is writing or running VBA macros that delete a file with the Kill statement and wants to avoid relying on the current directory.
- Observed behavior
- When the VBA Kill statement is supplied only a filename, it deletes from the current directory, which can change unexpectedly; a full path is safer.
Before you run a Kill macro, open WPS Spreadsheets, press Alt+F11 to confirm that the VBA editor opens, and note the exact full path of the target file or the folder of the active workbook.
Build a Full File Path from ActiveWorkbook and Kill the Target File
Use this method when you want the Kill statement to delete a file from the same folder as the active workbook, regardless of the current directory.
The VBA Kill statement accepts a pathname. If you pass only a filename, VBA resolves it against the current directory, which can change depending on the application state. Combining ActiveWorkbook.FullName, Left, and InStrRev builds a stable folder path.
In WPS Spreadsheets, press Alt+F11 to open the VBA editor window.
Click Insert > Module to create a new standard module.
Paste the following code: Dim fp As String: fp = ActiveWorkbook.FullName: fp = Left(fp, InStrRev(fp, "\")): fp = fp & "I_DONT_WANT_THIS_WORKBOOK.xlsx": Kill fp
Place the cursor inside the procedure and press F5 or click Run > Run Sub/UserForm to execute it.

Use an Explicit Full Path or a Wildcard in the VBA Kill Statement
Use this method when you know the exact target folder or want to delete multiple matching files in a specific path.
Delete Files by Full Path with VBA Kill in WPS Spreadsheets
WPS Spreadsheets supports VBA-compatible macros, so you can use the Kill statement with ActiveWorkbook.FullName to delete the intended file in your current workbook folder without switching to Microsoft Excel.
- 1. Open WPS Spreadsheets: Launch WPS Spreadsheets and open the workbook whose folder contains the file you want to delete.
- 2. Open the VBA editor: Press Alt+F11 to open the VBA editor.
- 3. Add the Kill code: Click Insert > Module and paste the full-path Kill code using ActiveWorkbook.FullName and InStrRev.
- 4. Run and verify: Run the macro with F5, then open the folder to confirm the target file is deleted.

Frequently Asked Questions
Why does Kill delete a file from the wrong folder when I only pass a filename?
Because VBA resolves a filename-only path against the current directory, which can change unexpectedly. Build the full path from ActiveWorkbook.FullName or hard-code the complete folder path before calling Kill.
How do I open the VBA editor in WPS Spreadsheets?
Open WPS Spreadsheets and press Alt+F11. You can then click Insert > Module to add a new module for the Kill macro.
Can I use wildcards with the VBA Kill statement?
Yes. Kill supports wildcards such as *.xlsx, but when no full path is supplied, the wildcard match runs in the current directory. Specify a full path to target the intended folder.
Does WPS Office support VBA macros like the Kill statement?
Yes. WPS Spreadsheets supports VBA-compatible macros, including file operations such as Kill, and works with Microsoft Excel macro-enabled formats.
What is the safest way to delete the active workbook's sibling file?
Use ActiveWorkbook.FullName with Left and InStrRev to extract the folder path, append the target filename, and pass that complete path to Kill.




