+ Reply to Thread
Results 1 to 4 of 4

Hide row after email sends

Hybrid View

  1. #1
    Registered User
    Join Date
    06-16-2012
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2010
    Posts
    24

    Hide row after email sends

    Hi everyone, i found this code on the rondebruin website and I'm trying to make it work better for my application. This code works great, it sends all the rows in seperate emails, but the problem is- this email is being sent to a phone as a text message. I need it to display the body of the email on the top line of every email, right now, if it determines that it needs to send out 10 messages, they all go out individually but the position of the body of the email will move down as the macro moves down in the list, this prevents the message being seen when the text arrives because the screen is so small. So how do I hide the row that it just emailed before it goes to the next email?

        With Sheets("SendRow")
        Set OutApp = CreateObject("Outlook.Application")
        
        For Each cell In .Columns("B").Cells.SpecialCells(xlCellTypeConstants)
            If cell.Value Like "?*@?*.?*" And LCase(cell.Offset(0, 1).Value) = "yes" Then
                .Range("A1:O100").AutoFilter Field:=2, Criteria1:=cell.Value
                Set rng = .AutoFilter.Range.SpecialCells(xlCellTypeVisible)
                Set OutMail = OutApp.CreateItem(0)
                With OutMail
                    .To = cell.Value
                    .Subject = "Hourly Rounding"
                    .HTMLBody = RangetoHTML(rng)
                    .Send
                End With
                Set OutMail = Nothing
                .AutoFilterMode = False
            End If
        Next cell
        
    cleanup:
            Set OutApp = Nothing
            With Application
                .EnableEvents = True
                .ScreenUpdating = True
            End With
            .Protect
        End With
        Sheets("Update").Select
    
    End Sub

  2. #2
    Registered User
    Join Date
    06-16-2012
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide row after email sends

    Here's the range to html that is given by the ron debruin website. Possibly there is something that can be changed in this part of the code to alter how the body is displayed?

    Function RangetoHTML(rng As Range)
        Dim fso As Object
        Dim ts As Object
        Dim TempFile As String
        Dim TempWB As Workbook
     
        TempFile = Environ$("temp") & "\" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
     
        'Copy the range and create a new workbook to past the data in
        rng.Copy
        Set TempWB = Workbooks.Add(1)
        With TempWB.Sheets(1)
            .Cells(1).PasteSpecial Paste:=8
            .Cells(1).PasteSpecial xlPasteValues, , False, False
            .Cells(1).PasteSpecial xlPasteFormats, , False, False
            .Cells(1).Select
            Application.CutCopyMode = False
            On Error Resume Next
            .DrawingObjects.Visible = True
            .DrawingObjects.Delete
            On Error GoTo 0
        End With
     
        'Publish the sheet to a htm file
        With TempWB.PublishObjects.Add( _
             SourceType:=xlSourceRange, _
             Filename:=TempFile, _
             Sheet:=TempWB.Sheets(1).Name, _
             Source:=TempWB.Sheets(1).UsedRange.Address, _
             HtmlType:=xlHtmlStatic)
            .Publish (True)
        End With
     
        'Read all data from the htm file into RangetoHTML
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
        RangetoHTML = ts.readall
        ts.Close
        RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
                              "align=left x:publishsource=")
     
        'Close TempWB
        TempWB.Close savechanges:=False
     
        'Delete the htm file we used in this function
        Kill TempFile
     
        Set ts = Nothing
        Set fso = Nothing
        Set TempWB = Nothing
    End Function
    
     
    Function GetBoiler(ByVal sFile As String) As String
        Dim fso As Object
        Dim ts As Object
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
        GetBoiler = ts.readall
        ts.Close
    End Function

  3. #3
    Registered User
    Join Date
    06-16-2012
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide row after email sends

    I think it's in this area of the code:

    If cell.Value Like "?*@?*.?*" And LCase(cell.Offset(0, 1).Value) = "yes" Then
                .Range("A1:O100").AutoFilter Field:=2, Criteria1:=cell.Value
                Set rng = .AutoFilter.Range.SpecialCells(xlCellTypeVisible)
                Set OutMail = OutApp.CreateItem(0)
                With OutMail
    It looks like it's pulling the entire range into the body, but i only want it to pull in the same row that the email address is in.
    In this spread sheet, the body of the message is in column A, the email address is in column B and column C refers to a "yes" or "no" which indicates if the conditions are met to send the email.

  4. #4
    Registered User
    Join Date
    06-16-2012
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide row after email sends

    figured it out, it was displaying the blank subject lines becuase every email address has a line if it's a "yes" or a "no" since the "no" values were hidden it displayed blank, now that i have a formula to carry the email address into the cell only if conditions are met, it does not display the blank rows anymore..

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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