Excel VBA and Google Apps Script both are used to automate tasks, create custom functions, integrate with different platforms, etc. However, automation is the most powerful feature offered by both Excel VBA and Google Apps Script to enhance productivity. In this article, we will compare the pros, cons, and use cases of Excel VBA and Google Apps Script with practical examples. This article will help you decide which one to use based on your requirements.
What Are Excel VBA and Google Apps Script?
- Excel VBA: Visual Basic Application (VBA) is a built-in programming language in Microsoft Excel. It allows users to automate tasks, create custom functions, and extend Excel’s capabilities.
- Google Apps Script: Apps Script is a cloud-based scripting tool that uses JavaScript language across all Google Workspace apps. It allows you to automate tasks and integrate services.
Pros and Cons of Excel VBA
Pros
- VBA supports deep integration with Excel’s features, allowing complex task automation.
- It offers custom Excel add-ins and UI customizations.
- It works without an internet connection.
- As it was introduced earlier you will get thousands of existing VBA solutions and robust community support.
Cons
- Limited to Windows as VBA doesn’t run on Excel for Web or most macOS versions.
- The VBA editor lacks modern IDE features like auto-completion.
- Requires learning a specific language (Visual Basic). VBA syntax is less beginner-friendly than JavaScript
- Limited compatibility across non-Microsoft platforms.
You can use Excel VBA to automate tasks when working offline. To create complex Excel solutions like dashboards, pivot tables, and custom functions. Excel builds robust financial or statistical models. Excel can process heavy and large data.
Pros and Cons of Google Apps Script
Pros
- Works on any device with internet access. Enables real-time collaboration with multiple users.
- Apps Script is based on JavaScript, a popular and versatile programming language.
- Seamlessly it integrates with Google Workspace (Docs, Sheets, Drive) and external APIs.
- Easy to send automatic emails.
- Scripts run in the cloud, reducing local resource usage.
Cons
- Requires a stable internet connection.
- Slower performance for heavy tasks. Can’t handle large data processing.
- Doesn’t support certain advanced spreadsheet features found in Excel.
- Requires Google account permissions, which may complicate collaboration in restricted environments.
You can use Google Sheets for collaborative projects, to get cross-platform access. To automate workflows using Google Workspace and external APIs. It performs simple data operations.
Use Case: Highlight Overdue Tasks and Send Email Automatically
Let’s show you simple and practical use cases for both Excel VBA and Google Apps Script to demonstrate their unique capabilities. Consider you have a task tracker where you list everything about your tasks like Task, Start date, End Date, Status, Assigned To, team members Email addresses, etc.
Excel VBA
Excel VBA will highlight the due date and send an email alert when a task is overdue using Outlook.
- Go to the Developer tab >> select Visual Basic.
- In the VBA editor, go to Insert tab >> select Module.
- Insert the following VBA code in the Module.
VBA Code:
Sub SendOverdueTaskEmails() Dim ws As Worksheet Dim lastRow As Long Dim i As Long Dim OutlookApp As Object Dim OutlookMail As Object Dim taskName As String Dim endDate As Date Dim assignedTo As String Dim emailAddress As String Dim taskStatus As String Dim todayDate As Date ' Set worksheet and determine the last row Set ws = ThisWorkbook.Sheets("Tasks") lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row todayDate = Date ' Initialize Outlook application On Error Resume Next Set OutlookApp = CreateObject("Outlook.Application") On Error GoTo 0 If OutlookApp Is Nothing Then MsgBox "Outlook is not available. Please make sure Outlook is installed and configured.", vbCritical Exit Sub End If ' Loop through tasks in the dataset For i = 2 To lastRow taskName = ws.Cells(i, 2).Value endDate = ws.Cells(i, 4).Value assignedTo = ws.Cells(i, 5).Value taskStatus = ws.Cells(i, 6).Value emailAddress = ws.Cells(i, 7).Value ' Check if task is overdue and not completed If endDate < todayDate And taskStatus <> "Completed" Then ' Highlight the due date cell in red ws.Cells(i, 4).Interior.Color = RGB(255, 0, 0) ' Create the email Set OutlookMail = OutlookApp.CreateItem(0) With OutlookMail .To = emailAddress .Subject = "Overdue Task Notification: " & taskName .Body = "Dear " & assignedTo & "," & vbCrLf & vbCrLf & _ "The task """ & taskName & """ was due on " & endDate & " and is now overdue." & vbCrLf & _ "Please review and update the status as soon as possible." & vbCrLf & vbCrLf & _ "Best regards," & vbCrLf & _ "Task Management Team" .Send End With Set OutlookMail = Nothing End If Next i ' Clean up Set OutlookApp = Nothing MsgBox "Emails sent for overdue tasks!", vbInformation End Sub
Explanation:
- Set the Worksheet: The Tasks sheet is referenced, and the last row with data is determined.
- Initialize Outlook: Checks if Outlook is installed and sets up an Outlook application object.
- Loop Through Tasks:
- Iterates through each task.
- Retrieves details like task name, end date, assigned person, email, and status.
- Check Overdue Tasks: If the task is overdue (End Date < Today) and not marked “Completed,” the following actions occur:
- Highlight in Red: The End Date cell is colored red (RGB(255, 0, 0)).
- Send Email: Creates and sends an email using Outlook with task details.
- Cleanup: Releases the Outlook object and shows a confirmation message.
- Save and Run the code. Go back to your worksheet.
This code automates both task reminders via email and highlights overdue dates in Excel.
Output:
VBA Insights:
- Requires Microsoft Excel and Outlook installed on the same system.
- Reads task data from Excel, checks overdue tasks, highlights them in red, and sends emails via Outlook.
- It requires more setup, as you need to ensure proper configuration of Outlook and valid email addresses.
- Sensitive to runtime errors if email addresses or Outlook aren’t set up properly.
Google Apps Script
Using Google Apps Script send an email alert for overdue tasks using Gmail.
Steps:
- Go to the Extension menu >> select Apps Script.
- Insert the following script into the code editor.
Apps Script Code:
function sendOverdueTaskemail() { // Open the active sheet const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Tasks"); // Get data range (assumes headers are in row 1) const range = sheet.getDataRange(); const data = range.getValues(); // Loop through rows starting from row 2 for (let i = 1; i < data.length; i++) { const taskName = data[i][1]; // Task Name in column B const endDate = new Date(data[i][3]); // End Date in column D const assignedTo = data[i][4]; // Assigned To in column E const status = data[i][5]; // Status in column F const email = data[i][6]; // Email Address in column G // Check if the task is overdue and not completed if (endDate < new Date() && status !== "Completed") sheet.getRange(i + 1, 4).setBackground("red"); { const subject = `Overdue Task Notification: ${taskName}`; const body = `Dear ${assignedTo},\n\nThe task "${taskName}" was due on ${endDate.toDateString()} and is now overdue. Please review and update the status as soon as possible.\n\nBest regards,\nTask Management Team`; // Send email GmailApp.sendEmail(email, subject, body); } } SpreadsheetApp.getUi().alert("Emails sent to the assigned individuals for overdue tasks!"); }
Explanation:
- Setup Sheet: Accesses the Tasks sheet and retrieves all data.
- Loop Through Tasks: Iterates through each row starting from the second.
- Check Overdue Tasks: If the End Date is past and the status isn’t “Completed”:
- Highlights the End Date cell in red.
- Send an email notification to the assigned person using Gmail.
- Completion: Displays a success message after processing.
Run the code and go back to your sheet to see the update. Check your mail account to see the email notifications.
Output:
Google Apps Script Insights:
- Runs directly in Google Sheets, using Gmail to send emails.
- Reads task data, highlights overdue tasks in red, and sends emails via Gmail.
- Simpler setup since Gmail is readily accessible in the Google ecosystem.
- No dependency on additional software like Outlook, making it lightweight.
Conclusion
Excel VBA is a powerful tool for offline tasks and complex Excel-specific operations, such as building advanced reports and manipulating large datasets, creating add-ins, etc.
Google Apps Script is useful in cloud-based environments, especially when working across platforms and integrating with Google Workspace apps.
These simple examples showcase the strengths of each tool, making it easier to choose the right one based on your requirements.
Get FREE Advanced Excel Exercises with Solutions!