Hi all,
I am currently using one of rondebruin's VBA codes for emailing.
However, I want to make the editing of the texts easier for the user depending on who the worksheets are being sent to. So ideally I would like to be able to reference the body of the the message to a worksheet:
The sections that I have amended that are not working is:
.Subject = Worksheets("Sheet1").Range("A1").Value
.Body = Worksheets("Sheet1").Range("A2").Value
Sub Mail_Every_Worksheet()
'Working in 2000-2007
Dim sh As Worksheet
Dim wb As Workbook
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object
TempFilePath = Environ$("temp") & "\"
If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007
FileExtStr = ".xlsm": FileFormatNum = 52
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
For Each sh In ThisWorkbook.Worksheets
If sh.Range("S1").Value Like "?*@?*.?*" Then
sh.Copy
Set wb = ActiveWorkbook
'-----------------------------------------
'CopyPasteValues Summary Worksheet
Module1.Macro1
'----------------------------------------------
TempFileName = sh.Name & " of Team Sheets"
Set OutMail = OutApp.CreateItem(0)
With wb
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=FileFormatNum
On Error Resume Next
With OutMail
.To = sh.Range("S1").Value
.CC = ""
.BCC = ""
.Subject = Worksheets("Sheet1").Range("A1").Value
.Body = Worksheets("Sheet1").Range("A1").Value
.Attachments.Add wb.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With
On Error GoTo 0
.Close SaveChanges:=False
End With
Set OutMail = Nothing
Kill TempFilePath & TempFileName & FileExtStr
End If
Next sh
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
Bookmarks