e-mail code

R

Ronbo

I am trying to e-mail two worksheets from a workbook using the following code
from Ron de Bruin;

Sub MailSheets()
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "dd-mm-yy h-mm-ss")
Application.ScreenUpdating = False
Sheets(Array("sheet 1", "sheet 2")).Copy
Set wb = ActiveWorkbook

With wb
.SaveAs "Part of " & ThisWorkbook.Name _
& " " & strdate & ".xls"
.SendMail "xxx.com", _
"This is the Subject line"
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub

The problem I have is that the two sheets contain code on activation. So
when the new workbook is created and a sheet activated, it errors from not
having a referenced module "open" used in (application.run "open" ).

Any suggestions as to what I can do to by pass the error, create without the
code or some other way to e-mail two worksheets from a workbook, is as always
greatly appreciated.
 
R

Ron de Bruin

Hi Ronbo

You can stop events from running like this

Application.EnableEvents = False
'Your code
Application.EnableEvents = True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top