For a client’s quotation system I have been using code to send an Excel sheet from a multipage workbook via MS Outlook. All was fine until recently.
The code would not execute completely but would throw up an error message when it got to the CreateObject line. The message related to “The specified module could not be found”.
A search of the error number (8007007e) revealed the following. If you add the optional variant ServerName (in this case “localhost”), the code runs as expected.
Original code in blue, update added in red:
Sub SendMail() Sheets("Quote - e-mail version").Select Application.Goto Reference:="CustomerCopy" Dim OutApp As Outlook.Application Dim OutMail As Outlook.MailItem Dim wb As Workbook Dim strdate As String strdate = Format(Now, "ddmmyyyy") Application.ScreenUpdating = False ActiveSheet.Copy Set wb = ActiveWorkbook With wb .SaveAs ThisWorkbook.Name _ & " " & strdate & ".xls" Set OutApp = CreateObject("Outlook.Application", "Localhost") Set OutMail = OutApp.CreateItem(olMailItem) With OutMail .To = "Edit_This_Text" .CC = "" .Subject = "Edit_This_Text" .Attachments.Add wb.FullName .Display End With .ChangeFileAccess xlReadOnly Kill .FullName .Close False End With Application.ScreenUpdating = True Set OutMail = Nothing Set OutApp = Nothing End Sub
This is just one part of the code and form required but gives an idea of the workaround.
Merry Christmas, Leigh