How to Use the Google Translate API from VBA in Access
Question details
The user needs a VBA function in Microsoft Access to automatically translate text stored in tables by passing the source text and target language to a translation API.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Automating text translation within an Access database using VBA scripts and the Google Translate API.
- Observed behavior
- The goal is to accept source text and a target language parameter, and return the translated text directly into the Access table or form without relying on a manual side pane.
Before integrating the Google Translate API, ensure you have an active Google Cloud account, a valid API key with billing enabled, and basic knowledge of making HTTP requests in the VBA editor.
Integrate Google Translate API using VBA HTTP Requests
Use MSXML2.XMLHTTP to send a REST API request to Google Cloud Translation and parse the JSON response in Access VBA.
To translate text programmatically, you need to send a POST request to the Google Translate REST API endpoint. Because VBA does not natively parse JSON data, utilizing VBA-JSON libraries (such as those found in the VBA-tools GitHub repository) will greatly simplify extracting the returned translation.
Log in to the Google Cloud Console, navigate to the API & Services dashboard, enable the 'Cloud Translation API', and generate a new API key.
Open the Access VBA Editor (Alt + F11). Go to Tools > References and check 'Microsoft XML, v6.0' to enable HTTP requests, and 'Microsoft Scripting Runtime' for dictionary support.
Create a VBA function that formats the endpoint URL (https://translation.googleapis.com/language/translate/v2), appends your API key, and sends the text and target language parameters using the MSXML2.XMLHTTP object.
Import a JSON parser module (like JsonConverter from Tim Hall's VBA-tools repository). Use it to extract the translated string from the API's response payload and assign it to your Access table record.
Use Microsoft Translator API as an Alternative
An alternative to Google Translate is the Microsoft Azure Translator API, which functions similarly via REST HTTP calls.
Looking for a Lightweight Alternative for Office Macros?
While Microsoft Access is a specialized database tool, many data processing and VBA macro tasks can be efficiently handled in powerful spreadsheets. WPS Office provides excellent compatibility with Microsoft Office formats and supports VBA macros, making it a powerful, free alternative for your daily data translation and management workflows.
- 1. Download the Installer: Visit the official WPS Office website and download the free installation package tailored for your operating system.
- 2. Install the Suite: Run the installer and follow the simple on-screen instructions to set up WPS Office on your computer.
- 3. Enable Macros: Open WPS Spreadsheet, navigate to the Developer tab, and start writing or importing your VBA macros to automate your tasks.

Frequently Asked Questions
Can I use the Google Translate API for free in VBA?
Google offers a limited free tier for the Cloud Translation API, but you still need to set up a billing account in the Google Cloud Console to obtain the active API key required for your VBA HTTP requests.
Why am I getting a JSON parsing error in my Access VBA code?
VBA does not have native support for parsing JSON data. You must use a third-party library, such as VBA-JSON from the VBA-tools GitHub repository, and ensure that the 'Microsoft Scripting Runtime' reference is checked in the VBA editor tools.
Is there a built-in translate function in Access or Excel VBA?
No, while Word and Excel have built-in translation task panes, there is no native =Translate() function available out-of-the-box. You must use REST APIs or web scraping techniques via VBA to pull automated translations directly into your database tables or spreadsheet cells.




