March 4, 2022 chan.t.h.chris

WORDLE in Excel VBA

An overview of how to code the Wordle from scratch using Excel VBA

Enjoy 5000+ Wordle Powered by Excel VBA for FREE

Enjoy 5000+ Wordle Powered by Excel VBA for FREE

Wordle, the daily word guessing game, is taking the world by storm. Have you ever found yourself craving for more Wordle?, Sadly, only one Wordle is available every day. Therefore, our solution is to power Wordle through Excel VBA so that you can play without limits. 

Let’s see how our Wordle works:

The power of Excel VBA

This project demonstrates the value of Excel VBA: a powerful yet easy to pick up programming language.

Use Excel VBA to develop powerful user-oriented Excel VBA applications, or even design a game

This week, we would go through the project objectives and the overall structure and flow of our project.

Wordle – Project Objectives

Before diving into the interface design and code writing, an important step is to brainstorm the objectives.

Here are the three objectives of our project:

  1. Handle the Gessing Logic
  2. Optimize the User Interface
  3. Provide Add-on Features on top of the original design

Handle the Wordle guessing logic

We want to teach the Excel to compare the guess to the answer. It can determine whether a letter is in the word and in the correct spot. It can reflect the result by displaying different colours (green, yellow, grey, etc) in both tiles and keyboard.

Design the user interface to mimic the real Wordle

We want the users to feel like they are playing the real Wordle. This involves optimization of every visual detail, such as the words, controls, spacing between controls, font (including font style and font colour), colours, icons, etc. Ideally, the user can operate the UserForm using either keyboard or mouse (through clicking the keys provided). We also want to prompt messages in different scenarios, such as congratulating the user on a correct guess, reminding the user to enter a valid word, etc.

Provide add-on features on top of the original design

Our biggest selling point is the availability to 5000+ Wordle. However, we want to take this one step further by designing add-on features. This includes choosing the Wordle number (which each number correlates with an answer) and allowing the player to refresh when finished. With the core design developed, it is possible to add further features in the future, such as a Countdown Challenge. For example, the user can guess as much words as you can in 10 minutes and compete with others.

Wordle – Project Structure in a Tree Diagram

Project structure in Wordle: UserForms, Modules, Class Modules and Worksheets

Project structure in Wordle: UserForms, Modules, Class Modules and Worksheets

UserForms

Wordle: Our main UserForm for Wordle guessing

Wordle: Our main UserForm for Wordle guessing

Wordle: Our main UserForm for Wordle guessing; most of the code resides here

HowToPlay: The UserForm to display rules of Wordle

HowToPlay: The UserForm to display rules of Wordle

HowToPlay: The UserForm to display rules of Wordle

Modules

Functions: customs functions to aid small repetitive tasks in guessing logic

OtherProcedures: miscellaneous sub procedures, such as UserForm initialization, Worksheet manipulation and Word list manipulation

UnusedCode: unused code blocks not included in the final design

Class Modules

clsImageWithEffect: Enable visual effects upon hovering on Restart and Help button

clsKey: Batch assign procedures to Keys to mimic keyboard usage

Worksheets

Wordle – Chris Chan – Excel VBA:

  • Cover page for the application; the only Worksheet visible to users
  • Provides a brief introduction to my website, enables access to my website and allows activation of Wordle

Backend Worksheets (hidden from users)

  1. Configuring the Keys: manual calculations to manipulate position of controls
  2. Answer: the word list containing the answers
  3. Original Word List: the crude word list with all the valid 5-letter words
  4. Design: an unprotected sheet with the design of cover page
  5. Final Word List: the manipulated word list with all the valid 5-letter words in column A; serves as the reference to determine whether a word is a valid 5-letter word

Overall flow

  1. Display the Wordle UserForm
  2. Input the Wordle No
  3. Guess the word by typing or clicking the keyboard provided
  4. Analyze the guess and display the results accordingly
  5. Disable further guesses if player successfully guess the word or used up the attempts; Allow the player to click refresh button to play the next Wordle.

Logic Flow in UserForm Wordle

Task Major Procedures Task details
1.      UserForm Initialization

UserForm_Initialize

  • User Interface Optimization
  • Batch assign procedures using class modules
2.      Handling Wordle Number input

tb_WordleNo_Keydown

tb_WordleNo_Change

  • Validate the Wordle Number
3.      Handling Wordle Guess – Allowing keyboard interaction and TextBox manipulation

tb_UserInput_KeyDown

tb_UserInput_Change

  • Determine the key pressed and act accordingly
  • Ensure the TextBox only contains at most 5 characters of A-Z by preventing unintended disruptions
  • Proceed to Part 4 if Enter key is pressed
4.      Analyzing the Guess

AnalyzeGuess

UpdateKeyboard

  • Validate and analyze the Guess
  • Format the tiles and keyboard accordingly

Summary and Reflection

Working on this project from scratch is a time-consuming and exhausting. Code development requires trial and error with tons of debugging. It took me 3 weeks to complete this project. I even woke up at 6AM to code so that I can work with maximum concentration and minimum distraction. This is all done while I am having a full-time job, tackling the exponential surge of COVID in Hong Kong and having irregular shifts. I am sorry that I don’t have time to publish blog posts.

Only one blog post cannot cover all the essential concepts and project design. Therefore, it would be awesome if you could stay tuned to our future updates. Next week, we would dive into the nitty-gritty, starting from the user interface design. Stay tuned!

Thank you for reading til the end. Please feel free to leave any comments down below 🙂 We greatly value your feedback since it is our drive to improve.

👇Check out our other articles on Excel VBA here, such as real-life projects and useful VBA techniques!

📝Excel VBA Projects

Expense Tracker – Apply VBA UserForm Fundamentals in a real-life project

Template Helper – Learn simple, core building blocks of Excel VBA in Template Helper

👍Excel VBA Techniques

Start Excel VBA Now – Uncover the secrets of Excel VBA right now

Beginner’s Guide to VBA UserForm – Learn everything you need to know about VBA UserForm