+ Reply to Thread
Results 1 to 8 of 8

Email macro will not read from my table

  1. #1
    Registered User
    Join Date
    09-22-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    11

    Unhappy Email macro will not read from my table

    I need help. I've been at this too long by myself. I can't find the solution, I'm just not that competent when it comes to VBA.

    My issue here is that I have a macro that will send a small email message to each participant within the list. The VBA code works correctly in a worksheet that does not have formulas or links within them. I've tested it in other work sheets with just the four cells I'm referencing in the VBA code. I do not know how to make the code read the Text only within the cell opposed to the Value. I believe that is where the VBA code is breaking.

    The Code:
    For Example it reads 4 cell values, determining whether or not to generate an email based off of "yes" and "send" in the last two cell. Works well with non-formula cells and in Cells A through D for test purposes, just not in mine at the moment.

    I've had to create this all encompassing Table so it can grow and be used by others at work, so it has to be pretty dummy-proof in case I'm not available lol. That is why the cells and there formulas are the way they are, as I will 'hide' most of the Columns from their views.

    The code:

    Sub Test2()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim cell As Range

    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")

    On Error GoTo cleanup
    For Each cell In Columns("Q").Cells.SpecialCells(xlCellTypeConstants)
    If cell.Value Like "?*@?*.?*" And _
    LCase(Cells(cell.Row, "R").Value) = "yes" _
    And LCase(Cells(cell.Row, "S").Value) <> "send" Then

    Set OutMail = OutApp.CreateItem(0)

    strbody = "Hello " & Cells(cell.Row, "P").Value _
    & vbNewLine & vbNewLine & _
    "This is line 1" & vbNewLine & _
    "This is line 2" & vbNewLine & _
    "This is line 3" & vbNewLine & _
    "This is line 4"

    On Error Resume Next
    With OutMail
    .To = cell.Value
    .CC = ""
    .BCC = ""
    .Subject = "Report Reminder"
    .Body = strbody

    .Display
    End With
    On Error GoTo 0
    Cells(cell.Row, "D").Value = "send"
    Set OutMail = Nothing
    End If
    Next cell

    cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True
    End Sub



    I've also attached a sample of the excel sheet if would like to see or edit in there.

    I'd appreciate anything at this point, I just don't get it...
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Email macro will not read from my table

    The email addresses in column Q are the results of formulas so they aren't picked up by SpecialCells(xlCellTypeConstants).

    Try this instead.
    Please Login or Register  to view this content.
    Last edited by Norie; 02-10-2015 at 12:17 AM.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Email macro will not read from my table

    Norie is right so
    Try using this:-
    Please Login or Register  to view this content.
    instead of
    Please Login or Register  to view this content.
    in the code and tell if it works for you.
    Regards,
    Vikas Gautam
    Excel-buzz.blogspot.com

    Excel is not a matter of Experience, its a matter of Application.

    Say Thanks, Click * Add Reputation

  4. #4
    Registered User
    Join Date
    09-22-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: Email macro will not read from my table

    Thank you both, so very much!
    Both lines worked, perfectly. I assume they both do the same, but what is the difference may I ask?

  5. #5
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Email macro will not read from my table

    Not a big difference.
    Noorie's line skips heading row and mine takes it.

  6. #6
    Registered User
    Join Date
    09-22-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: Email macro will not read from my table

    That's what I thought but I didn't want stick my neck out and guess openly.

    If you have a moment, I figure I might as well ask you while I have your attention.
    Is there a way in which I can hyper-link text within this body? Every time I got to use .HTMLbody, it collapses my message. Also, I cannot find a clear answer possibly because I am asking the wrong question or this would require a new series of lines.

  7. #7
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Email macro will not read from my table

    Yes, I required a new series of lines.
    If you know Html (I don't know HTML) you can make a string of HTML code and assign it to .HTMLBODY.

    Moreover as a guess, you can use excel ranges as well. Make some hyperlinks in some cell in the sheet. and use the code in the link below to send mail:-
    Emailing a Selection or Range.

  8. #8
    Registered User
    Join Date
    09-22-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: Email macro will not read from my table

    Thanks again

+ 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. Macro to email set of cells as table that runs every 30 minutes
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-19-2013, 08:53 AM
  2. Macro to email reports out of a Pivot Table. Help!
    By AllExcel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-07-2012, 05:32 PM
  3. Macro: open file, read data, create table, vlookup
    By doctorspears in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-26-2011, 12:54 PM
  4. outlook macro to pull in a table from excel file to email.
    By chewwy in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 08-18-2009, 03:10 PM
  5. email a read only doc
    By Vlegg in forum Excel General
    Replies: 1
    Last Post: 05-11-2006, 03:00 PM

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