logo
search
VBA & Macro Problems

How to Send an Email via VBScript When Excel Workbook is Unprotected

Olivia MillerOlivia Miller Oct 12, 2026 870 views

Question details

The user needs a VBScript solution to monitor an Excel workbook and send an automated email alert if the workbook's structure protection has been removed.

How to Send an Email Using VBScript When an Excel Workbook is Unprotected
Product
Microsoft Excel, Microsoft Outlook, VBScript
Device & OS
not provided
Scenario
Automating security monitoring for an Excel file to alert administrators when a user removes the workbook structure protection.
Observed behavior
The user requires an external script that evaluates the ProtectStructure property of an Excel file and triggers an Outlook email if the property returns False.
Before you start

Ensure that both Microsoft Excel and Microsoft Outlook are installed and configured on your system, as this script relies on their COM objects to function properly.

Solution 1Recommended

Create a VBScript to Check Workbook Protection and Send Email

Write a standalone VBScript (.vbs) file that opens the specified Excel file, evaluates its protection status, and triggers an Outlook email if unprotected.

This approach uses Windows Script Host to invoke the Excel.Application and Outlook.Application COM objects. It operates independently of Excel VBA macros, making it ideal for external monitoring or scheduled tasks.

1
Open a text editor

Open Notepad or your preferred plain text editor to begin creating the VBScript file.

2
Paste the VBScript code

Insert the following code into your file: Dim excelApp, workbook, outlookApp, mail Set excelApp = CreateObject("Excel.Application") Set workbook = excelApp.Workbooks.Open("C:\Path\To\Excel\File.xlsx") If workbook.ProtectStructure = False Then Set outlookApp = CreateObject("Outlook.Application") Set mail = outlookApp.CreateItem(0) mail.To = "recipient@example.com" mail.Subject = "Excel file unprotected" mail.Body = "The Excel file has been unprotected." mail.Send End If workbook.Close False excelApp.Quit Set mail = Nothing Set outlookApp = Nothing Set workbook = Nothing Set excelApp = Nothing

3
Update the script variables

Modify the file path ("C:\Path\To\Excel\File.xlsx"), recipient email address, subject line, and body text to match your specific requirements.

4
Save and execute the script

Save the file with a .vbs extension (for example, CheckProtection.vbs). Double-click the file in Windows File Explorer to execute the script and test the automation.

Create a VBScript to Check Workbook Protection and Send Email
Outlook Security Prompts: Depending on your system's anti-virus status and Outlook security settings, you may see a warning prompt asking to allow an external program to send an email on your behalf.
Free Microsoft Office alternative

Try WPS Office for Seamless Spreadsheet Management

If you frequently work with complex spreadsheets, automation, and macros, consider switching to WPS Office. It provides a lightweight, highly compatible environment for handling advanced Office tasks without the hefty subscription fees.

Highly compatible with Microsoft Excel formats (.xls, .xlsx, .xlsm)Built-in VBA editor for robust macro automationLightweight setup with fast launch speedsFamiliar user interface requires no learning curve
microsoft office alternative - wps office

Frequently Asked Questions

Why is my script giving an 'ActiveX component can't create object' error?

This error typically occurs if Microsoft Excel or Outlook is not installed on the machine running the script, or if the COM registry keys for these applications are corrupted.

How can I automate this script to run every day?

You can use the Windows Task Scheduler to create a new task, set a daily trigger, and set the action to execute your saved .vbs file automatically in the background.

Does this script work if the Excel file is already open by another user?

If the file is locked by another user on a network, the script will open it in Read-Only mode. It can still check the ProtectStructure property, but ensure your script uses 'workbook.Close False' to close it without saving and avoid read-only prompt dialogs.