Intermediate35–45 minutes

Build a complete Excel Snake game

Start with a blank workbook and finish with a playable game. The sample module includes the board, snake movement, food, collision detection, score, keyboard controls, timer cleanup, and clear error messages.

Download the complete VBA module
Excel Snake game board

You need

Desktop Excel with VBA support

You will create

A 20 × 20 playable Snake board

Final check

Move, score, collide, stop, restart

Reproducible setup

Follow these steps in order

  1. 1

    Create the workbook

    Open a blank workbook, rename the first worksheet to Game, then save the file as Excel Macro-Enabled Workbook (*.xlsm).

  2. 2

    Import the complete module

    Press Alt+F11, choose File > Import File, and select excel-snake-complete.bas from the download below.

  3. 3

    Save and return to Excel

    Press Ctrl+S, close the VBA editor, and return to the Game sheet. Keep Excel’s global macro protection enabled.

  4. 4

    Start the game

    Press Alt+F8, select StartSnakeGame, and choose Run. The board appears in B2:U21.

  5. 5

    Play and stop safely

    Use the arrow keys to steer. Eat red cells to score. Press Q or run StopSnakeGame before closing the workbook.

Expected result

Your workbook is complete when…

  • ✓ The board appears in cells B2:U21.
  • ✓ Arrow keys change direction without reversing into the snake.
  • ✓ Red food moves after it is eaten and the score increases.
  • ✓ Wall or body collisions end the game with a score message.
  • ✓ Q stops the timer and restores normal arrow-key behavior.

Security boundary

Trust one workbook, not every macro

This tutorial creates code you can inspect yourself. Keep the global “Disable VBA macros with notification” protection in place. Do not switch Excel to “Enable all macros.” Excel for the web cannot run this project.

When something goes wrong

Troubleshooting

“Subscript out of range” appears

The worksheet is not named Game. Rename it exactly, with no extra spaces, then run StartSnakeGame again.

Arrow keys scroll the worksheet

Run StartSnakeGame first and keep the workbook active. If a previous run stopped unexpectedly, run StopSnakeGame once, then start again.

The macro is blocked

Use desktop Excel. On Windows, close Excel and check the .xlsm file’s Properties dialog for an Unblock option. Only unblock this file if you trust it; never enable all macros globally.

The game continues after switching sheets

Press Q or run StopSnakeGame. The module cancels its scheduled tick and restores normal arrow-key behavior.

The game feels too fast or slow

In ScheduleNextTick, change “/ 2” to “/ 1” for a slower one-second tick, or “/ 3” for a faster tick.

Ready to compare your build?

Download the published Snake package to compare the player experience, or browse the game details for compatibility and package verification notes.