+ Reply to Thread
Results 1 to 3 of 3

Email Message body with reference to cell using VBA coding

  1. #1
    Registered User
    Join Date
    04-22-2013
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Email Message body with reference to cell using VBA coding

    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

  2. #2
    Forum Contributor ragavan.sridar1's Avatar
    Join Date
    11-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010, Excel 2003
    Posts
    208

    Re: Email Message body with reference to cell using VBA coding

    try it this way..


    Please Login or Register  to view this content.
    Thanks!
    Raga.

    Please,mark your thread [SOLVED] if you received your answer.

    Click the little star * below, to give some Rep if you think an answer deserves it.

    I learnt so many things from these links.

  3. #3
    Registered User
    Join Date
    04-22-2013
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Email Message body with reference to cell using VBA coding

    I have tried "sheets" instead of "Worksheets" and it still sends out the email with a blank subject heading & content

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1