SYMPTOMS
When you open a workbook in e-mail or save the attachment and open the
workbook in Microsoft Excel, you may receive the following error
message:
This program has performed an illegal operation and will be shut down.
If the problem persists, contact the program vendor.
When you click
Details, you receive an error message similar to the
following:
Excel.exe caused an invalid page fault in module
Excel.exe at 015f:3047004d.
WORKAROUND
Use either of the following methods to work around this problem.
Method 1: Use Two, Separate Macros
In order to use the
Delete method and the
SendMail property, you can use two separate macro subroutines. However, you would run each macro individually. In the following example, you would first run
Sub DelSheet, and then, when it is finished, you would run
Sub SendEmail.
Sub DelSheet()
Sheet2.Delete
End Sub
Sub SendEmail()
ActiveWorkbook.SendMail ""
End Sub
Method 2: Use the OnTime Method
To use both the
Delete method and
SendMail property in the
same macro subroutine, you can use the
OnTime method. The
OnTime method runs a specified macro at a specified time interval. By using this method, you can delete a worksheet and wait N seconds before sending the e-mail, where N represents the number of seconds to wait. The example below waits 5 seconds before running the SendEmail macro procedure:
Sub DelSheet()
Sheet2.Delete
Application.OnTime Now + TimeValue("0:0:05"), "SendEmail"
End Sub
Sub SendEmail()
ActiveWorkbook.SendMail ""
End Sub