How to Fix Excel 365 Currency-to-Words VBA Code Error
Question details
The user is experiencing errors when running a VBA macro intended to convert numerical currency amounts into written words in Excel 365.

- Product
- Microsoft Excel 365
- Device & OS
- not provided
- Scenario
- Copying a currency-to-words VBA code snippet from a website and pasting it into the Excel VBA Editor to automate amount formatting.
- Observed behavior
- The VBA code fails to execute or returns syntax errors due to hidden formatting, blank lines, or mismatched currency types (e.g., Dollars instead of Rupees).
Ensure you save your Excel workbook as a Macro-Enabled Workbook (.xlsm) before editing the VBA editor so your code modifications are preserved.
Clean Up Formatting and Adjust the Currency Code
Remove hidden web formatting and blank lines from the pasted code, and modify the strings to match your local currency.
When you copy VBA code directly from a web browser, invisible characters, non-breaking spaces, and empty lines are often carried over. The Excel VBA compiler cannot process these, resulting in syntax errors. Additionally, most default currency-to-words macros are hardcoded for US Dollars and Cents.
Press Alt + F11 in Excel to launch the Microsoft Visual Basic for Applications window, and double-click the Module containing your pasted code.
Manually delete any irregular blank lines or strange symbols scattered between the lines of the code to ensure the syntax flows continuously.
Locate the words 'Dollars' and 'Cents' within the code strings. Replace them with your required currency, such as 'Rupees' and 'Paise', if you are working with Indian currency.
Go to Debug > Compile VBAProject in the top menu to verify that no syntax errors remain, then save your changes.

Save the Macro as an Excel Add-in for Global Use
Convert your corrected currency-to-words macro into an Add-in so the function can be used across all your Excel workbooks automatically.
Run Currency-to-Words VBA Macros Smoothly in WPS Office
WPS Office natively supports Excel VBA macros, allowing you to seamlessly run your currency-to-words scripts without formatting conflicts or heavy system resource usage.
- 1. Install WPS Office: Download and install the latest version of WPS Office for free from the official website.
- 2. Open Your Macro Workbook: Open your .xlsm file containing the currency-to-words script in WPS Spreadsheet.
- 3. Access the VBA Editor: Navigate to the 'Tools' tab on the ribbon and click 'Macro' to open the familiar VBA interface.
- 4. Execute the Code: Paste your clean code and run the custom formula smoothly across your spreadsheets.

Frequently Asked Questions
Why does copied VBA code often fail to compile in Excel?
Code copied directly from websites frequently brings along invisible HTML formatting, non-breaking spaces, or incorrect line breaks. The Excel VBA compiler cannot interpret these hidden characters, which leads to syntax and compile errors.
How can I adapt the VBA macro for different currencies?
You need to open the VBA code and manually find the string variables defining the currency names. Simply replace instances of 'Dollars' and 'Cents' with your target currency names, such as 'Euros' and 'Cents' or 'Pounds' and 'Pence'.
Do I have to share the Add-in file for others to use my macro?
Yes, if you configure the currency-to-words macro as an Excel Add-in (.xlam), other users will also need a copy of that .xlam file. They must install and enable it via File > Options > Add-ins on their own computers.




