+ Reply to Thread
Results 1 to 10 of 10

Adding to body in email

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-07-2013
    Location
    mo
    MS-Off Ver
    Excel 2010
    Posts
    453

    Adding to body in email

    Hello, I need to add "Here are the numbers" to the top of the body in the VBA below. Thanks for help

    Sub CreateMail()

    Dim rngSubject As Range
    Dim rngTo As Range
    Dim rngBody As Range
    Dim objOutlook As Object
    Dim objMail As Object

    Set objOutlook = CreateObject("Outlook.Application")
    Set objMail = objOutlook.CreateItem(0)

    With ActiveSheet
    Set rngTo = .Range("O16")
    Set rngSubject = .Range("O17")
    Set rngBody = .Range(.Range("D15"), .Range("D25").End(xlDown))
    End With
    rngBody.Copy

    With objMail
    .To = rngTo
    .Subject = rngSubject
    .Display 'Instead of .Display, you can use .Send to send the email _
    or .Save to save a copy in the drafts folder
    End With
    SendKeys "^({v})", True

    Set objOutlook = Nothing
    Set objMail = Nothing

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Adding to body in email

    Please use code tags when posting. See Forum Rule No. 3.

    Maybe:

    Sub CreateMail()
    
    Dim rngSubject As Range
    Dim rngTo As Range
    Dim rngBody As Range
    Dim objOutlook As Object
    Dim objMail As Object
    
    Set objOutlook = CreateObject("Outlook.Application")
    Set objMail = objOutlook.CreateItem(0)
    
    With ActiveSheet
    Set rngTo = .Range("O16")
    Set rngSubject = .Range("O17")
    Set rngBody = "Here are the numbers " & .Range(.Range("D15"), .Range("D25").End(xlDown))
    End With
    rngBody.Copy
    
    With objMail
    .To = rngTo
    .Subject = rngSubject
    .Display 'Instead of .Display, you can use .Send to send the email _
    or .Save to save a copy in the drafts folder
    End With
    SendKeys "^({v})", True
    
    Set objOutlook = Nothing
    Set objMail = Nothing

  3. #3
    Forum Contributor
    Join Date
    08-07-2013
    Location
    mo
    MS-Off Ver
    Excel 2010
    Posts
    453

    Re: Adding to body in email

    Thanks for the help, Im getting an error saying:

    Run-time error '13':
    Type mismatch

    and this is the line highlighted

    Set rngBody = "Here are the numbers " & .Range(.Range("D15"), .Range("D25").End(xlDown))

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Adding to body in email

    Outlook is not really an application I work with often. My client is Lotus Notes. But maybe try changing that line.

    Set rngBody = "Here are the numbers " & .Range(.Range("D15"), .Range("D25").End(xlDown)) .Text
    If that doesn't work, then maybe someone else can provide assistance.

  5. #5
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: Adding to body in email

    rngBody is declared as a Range, try declaring it as a String instead using John's code.

    OR

    Sub CreateMail()
    
    Dim rngSubject As Range
    Dim rngTo As Range
    Dim rngBody As Range
    Dim objOutlook As Object
    Dim objMail As Object
    
    Set objOutlook = CreateObject("Outlook.Application")
    Set objMail = objOutlook.CreateItem(0)
    
    With ActiveSheet
    Set rngTo = .Range("O16")
    Set rngSubject = .Range("O17")
    Set rngBody = .Range(.Range("D15"), .Range("D25").End(xlDown))
    End With
    
    
    With objMail
    .To = rngTo
    .Subject = rngSubject
    .Display 'Instead of .Display, you can use .Send to send the email _
    or .Save to save a copy in the drafts folder
    .Body = "Here are the numbers " & rngBody
    End With
    
    
    Set objOutlook = Nothing
    Set objMail = Nothing
    Last edited by VBA FTW; 09-20-2013 at 03:06 PM.

  6. #6
    Forum Contributor
    Join Date
    08-07-2013
    Location
    mo
    MS-Off Ver
    Excel 2010
    Posts
    453

    Re: Adding to body in email

    Thanks, I tried both and still has an issue. VBA FTW the error is coming back with:

    Run-time error '13':
    Type mismatch

    and this is the line highlighted

    .Body = "Here are the numbers " & rngBody

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Adding to body in email

    Can you post the code you are using?

  8. #8
    Forum Contributor
    Join Date
    08-07-2013
    Location
    mo
    MS-Off Ver
    Excel 2010
    Posts
    453

    Re: Adding to body in email

    Here is my code. This works to get the part I want selected into the body of my email. What I want to do, which I have been tying to get work for a week, is add "here is this weeks numbers" to the body of the email. If I could do that that would work. What would be ideal if I could, instead of a set text like "here is this weeks numbers", and the contents of my text box to the email and then the " Set rngBody = .Range(.Range("D15"), .Range("K25").End(xlDown)) " after. Attached is the examples of what I am tring to do.



    Sub CreateMail()

    Dim rngSubject As Range
    Dim rngTo As Range
    Dim rngBody As Range
    Dim objOutlook As Object
    Dim objMail As Object

    Set objOutlook = CreateObject("Outlook.Application")
    Set objMail = objOutlook.CreateItem(0)

    With ActiveSheet
    Set rngTo = .Range("O16")
    Set rngSubject = .Range("O17")
    Set rngBody = .Range(.Range("D15"), .Range("K24").End(xlDown))
    End With
    rngBody.Copy

    With objMail
    .to = rngTo
    .Subject = rngSubject
    .Display 'Instead of .Display, you can use .Send to send the email _
    or .Save to save a copy in the drafts folder
    End With
    SendKeys "^({v})", True

    Set objOutlook = Nothing
    Set objMail = Nothing

    End Sub
    Attached Images Attached Images

  9. #9
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Adding to body in email

    Post #2 - Please use code tags when posting.

    Post #5 - by VBA FTW - rngBody is declared as a Range, try declaring it as a String instead using John's code.

    Post #8 - I don't see any .Body in your current code?

  10. #10
    Forum Contributor
    Join Date
    08-07-2013
    Location
    mo
    MS-Off Ver
    Excel 2010
    Posts
    453

    Re: Adding to body in email

    Sub CreateMail()
    
    
    
    Dim rngSubject As Range
    Dim rngTo As Range
    Dim rngBody As Range
    
    Dim objOutlook As Object
    Dim objMail As Object
    
    Set objOutlook = CreateObject("Outlook.Application")
    Set objMail = objOutlook.CreateItem(0)
    
    With ActiveSheet
    Set rngTo = .Range("O16")
    Set rngSubject = .Range("O17")
    Set rngBody = .Range(.Range("D15"), .Range("K25").End(xlDown))
    End With
    rngBody.CopyPicture xlScreen, xlBitmap
    
    With objMail
    .to = rngTo
    .Subject = rngSubject
    .Display 'Instead of .Display, you can use .Send to send the email _
    or .Save to save a copy in the drafts folder
    .Body = "TextBox3.Text"
    
    
    
    
    End With
    SendKeys "({END})"
    SendKeys "({ENTER})"
    SendKeys "({ENTER})"
    SendKeys "^({v})", True
    
    Set objOutlook = Nothing
    Set objMail = Nothing
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Send New Email W/ Body of Received Email, Then Delete Sent Email
    By edneal2 in forum Outlook Formatting & Functions
    Replies: 2
    Last Post: 07-01-2013, 12:45 AM
  2. Email Hyperlink Adding Body/Subject Text
    By jpmorgan123 in forum Excel General
    Replies: 1
    Last Post: 05-12-2013, 12:41 PM
  3. Adding body to email via VBA for an outlook template
    By teekayy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-09-2012, 04:19 AM
  4. [SOLVED] Adding a disclaimer changes image in email body
    By johncassell in forum Outlook Programming / VBA / Macros
    Replies: 3
    Last Post: 04-05-2012, 08:42 AM
  5. Adding text to body of email with workbook attached.
    By aph in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-05-2005, 11:11 AM

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