Fix Excel VBA Macro to Email a Workbook Without Showing Outlook
Question details
The user needs to troubleshoot a VBA macro that hides a worksheet button, saves the file, and emails the workbook via Outlook without displaying the email window.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Running a VBA macro to automate sending the current workbook as an email attachment via Outlook in the background.
- Observed behavior
- The macro fails to execute properly, resulting in nothing happening when the submit button is clicked, often due to incorrect shape names or security restrictions.
Ensure your workbook is saved as an Excel Macro-Enabled Workbook (.xlsm) and that Microsoft Outlook is installed, active, and logged into an email account on your device.
Verify and Correct the Button Shape Name in VBA
Fix the most common cause of macro failure by ensuring the shape name in your code exactly matches the object on your worksheet.
When a macro attempts to hide or interact with a shape (like a Submit button) before sending an email, an incorrect shape name in the code will cause the script to fail silently, especially if error handling is turned off.
Navigate to the Home tab on the Excel ribbon, click on 'Find & Select' in the Editing group, and choose 'Selection Pane'.
Look at the list in the Selection Pane to find the exact name of your submit button. Take note of spacing, such as 'CommandButton1' versus 'CommandButton 1'.
Press ALT + F11 to open the VBA editor. Locate the line of code that hides the shape and update it to match the exact name, for example: ActiveSheet.Shapes("CommandButton1").Visible = False.
If your code contains the line 'On Error Resume Next', temporarily comment it out by adding an apostrophe (') at the beginning. Run the macro again to see if any specific error messages pop up.

Configure Macro Security and Outlook Programmatic Access
Ensure that Excel allows the macro to run and that Outlook permits automated sending without manual intervention.
Automate Email Tasks with WPS Spreadsheets
WPS Office provides robust support for VBA macros, allowing you to seamlessly automate tasks like hiding buttons, saving documents, and sending workbooks via email. It offers a familiar interface and excellent compatibility with Microsoft Excel macros.
- 1. Open Your Macro-Enabled File: Launch WPS Spreadsheets and open your existing .xlsm workbook containing the email automation script.
- 2. Access the Developer Tools: Navigate to the Developer tab on the ribbon. If it is hidden, enable it from the customized ribbon settings.
- 3. Open the VBA Editor: Click the 'Visual Basic' icon to access the integrated VBA editor where you can check shape names and debug your Outlook automation code.
- 4. Run and Share: Execute your macro directly within WPS to securely send the workbook in the background, or use WPS Office's built-in sharing features.

Frequently Asked Questions
Why does my VBA macro fail to send an email through Outlook silently?
This typically occurs due to an incorrect shape name referenced in the code, disabled macro settings in the Excel Trust Center, or Outlook's programmatic access security blocking automated actions to prevent malware.
How do I find the exact name of a button in Excel for my VBA code?
Navigate to the Home tab, click on 'Find & Select' in the Editing group, and open the 'Selection Pane'. This side panel displays the exact names of all shapes, images, and buttons currently on your worksheet.
How can I see errors if my Excel macro fails but does nothing?
If your VBA script includes the line 'On Error Resume Next', it actively suppresses error alerts. Comment out or delete this line temporarily, then run the macro again to reveal the exact error code and description.
Can I send an email using VBA without the Outlook window popping up?
Yes. In your VBA Outlook MailItem object block, ensure you use the '.Send' command instead of the '.Display' command. This instructs Outlook to move the email directly to the outbox and send it in the background.




