Fix Excel VBA Macros That Fail in Step Mode on Mac with WPS Office
Question details
The user needs to resolve a VBA macro that runs normally but fails when executed in step mode on Mac because undeclared loop variables are assigned an unsuitable data type.

- Product
- WPS Office Spreadsheets and Excel VBA macros
- Device & OS
- macOS
- Scenario
- The user is stepping through an Excel VBA macro on a Mac and encounters a runtime failure that does not occur during normal execution.
- Observed behavior
- The macro completes normally during regular execution, but fails or stops incorrectly only in step mode; undeclared variables are assigned unsuitable data types.
Open the macro-enabled workbook in WPS Office Spreadsheets or Excel, enable the Developer tab, and open the Visual Basic Editor. Confirm the failing macro is visible in the project tree before you modify code.
Enable Option Explicit and Declare Loop Counters as Long in the VBA Editor
Use this fix when a VBA macro fails only in step mode but runs normally; it forces explicit declarations and prevents counters from receiving incorrect data types.
Step-mode failures are often caused by undeclared loop variables. Option Explicit makes undeclared variables visible as compile errors, while declaring loop counters as Long prevents type-mismatch and overflow issues during line-by-line execution.
In WPS Office Spreadsheets or Excel on Mac, go to the Developer tab and click Visual Basic, or press Option+F11, to open the VBA editor.
In the Project Explorer, select the module that contains the failing macro. At the top of the code window, before any procedures, type Option Explicit.
Find each For...Next or Do...Loop loop in the macro and identify the counter variables, such as i and j.
At the start of the subroutine, add Dim i As Long and Dim j As Long. Remove or correct any earlier declarations that use Integer or Variant for these counters.
Click Debug > Compile VBAProject, then run the macro normally and use Debug > Step Into to confirm the macro no longer fails in step mode.

Use WPS Office to Fix Step-Mode VBA Macro Failures on Mac
WPS Office Spreadsheets includes a VBA editor for inspecting and correcting macro code. Enable Option Explicit, declare loop counters as Long, and verify that the macro runs consistently in normal and step mode.
- 1. Open the macro-enabled workbook: Launch WPS Office Spreadsheets and open the Excel macro-enabled workbook that fails in step mode.
- 2. Open the VBA editor: Go to Developer > Visual Basic in WPS Office to access the macro code.
- 3. Apply the Option Explicit fix: Add Option Explicit at the top of the module and declare all loop counters as Long, such as Dim i As Long.
- 4. Compile and rerun the macro: Use Debug > Compile VBAProject, then test the macro in normal mode and step mode to confirm the failure is resolved.

Frequently Asked Questions
Why does my Excel VBA macro work normally but fail when I step through it on Mac?
This usually happens when loop counters or other variables are not declared explicitly. In step mode, VBA may evaluate types differently. Enable Option Explicit and declare counters as Long to make execution consistent.
Do I need to declare every variable in VBA if I use Option Explicit?
Yes. Once Option Explicit is added to a module, every variable must be declared with Dim, Private, Public, ReDim, or Static before it is used, otherwise the VBA editor shows a compile error.
Can WPS Office open Excel macro-enabled workbooks?
WPS Office Spreadsheets can open and save Excel .xlsm macro-enabled workbooks. Use Developer > Visual Basic to inspect and edit macro code in a familiar VBA environment.
Will changing loop counters from Integer to Long affect my macro result?
For most loop counters, changing Integer to Long does not change the result and can prevent overflow or type-mismatch issues. Use Long when a loop may exceed the Integer range or when step mode behaves differently.
Is downgrading Excel necessary to fix step-mode macro failures?
No. Downgrading Excel is usually unnecessary for this symptom. Correcting variable declarations, especially declaring loop counters as Long, is the recommended fix.




