VBA & Macro Problems

How to Specify a File Path with the VBA Kill Statement in WPS Spreadsheets

Maira MehtabMaira Mehtab Nov 13, 2026 869 views

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.

How to Specify a File Path with the VBA Kill Statement in WPS Spreadsheets
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 start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In WPS Spreadsheets, press Alt+F11 to open the VBA editor window.

2
Insert a module

Click Insert > Module to create a new standard module.

3
Paste the full-path code

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

4
Run the macro

Place the cursor inside the procedure and press F5 or click Run > Run Sub/UserForm to execute it.

Build a Full File Path from ActiveWorkbook and Kill the Target File
File deleted from the intended folder: The Kill statement now receives the active workbook's folder path, so it removes the target file even if the current directory changes.
WPS Spreadsheets VBA

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. 1. Open WPS Spreadsheets: Launch WPS Spreadsheets and open the workbook whose folder contains the file you want to delete.
  2. 2. Open the VBA editor: Press Alt+F11 to open the VBA editor.
  3. 3. Add the Kill code: Click Insert > Module and paste the full-path Kill code using ActiveWorkbook.FullName and InStrRev.
  4. 4. Run and verify: Run the macro with F5, then open the folder to confirm the target file is deleted.
Deletes the target file from the active workbook folder instead of the unpredictable current directorySupports wildcard and full-path Kill macros for batch cleanupFree, lightweight alternative to Microsoft Excel for VBA and macro tasksOpens and saves .xlsx, .xlsm and other Microsoft Excel workbook formatsFamiliar VBA editor with Alt+F11 access for easy macro editing
microsoft office alternative - wps office

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.