Email a range from Excel not working

L. Howard

Well-known Member
Joined
Oct 16, 2012
Messages
4,514
Excel 2010
Windows Live Mail 2011 (on Xfinity by Comcast Home Page)

The Sub Countup() & Sub Realcount() are from a Google search.
The Sub Mail_Range() is from Ron DeBruin's site.
The mission is to send a range from an Excel sheet to an email address.

I enter a count down time in E1 on sheet 3 and run Sub Countup.

When time expires Mail_Range is called.

My screen lights up with a Windows Live Mail "boot-up" box and then my mail page and the I get an alert message box
saying Windows Live is trying to send you a mail message...Send, Don't Send, Cancel.

I get this box three times as per the code has a I = 1 to 3 line in it to send the Excel mail message.

If I understand the code correctly, I should get the Excel worksheet Range(A1:B5) sent to me. (Text strings in about six of the cells)

So, I guess the hang up here is with my mail provider..????
I tried changing the email address to my wifes email, same results. (Same provider as mine however so maybe that is not a good troubleshooter method.)

Any ideas?

Regards,
Howard

Rich (BB code):
Option Explicit
Sub Countup()
 
Dim CountDown As Date
 
CountDown = Now + TimeValue("00:00:01")
 
Application.OnTime CountDown, "Realcount"
 
End Sub


Sub Realcount()
 
Dim count As Range
 
Set count = [E1]
 
count.Value = count.Value - TimeSerial(0, 0, 1)
 
If count <= 0 Then
 
'MsgBox "Countdown complete."
Mail_Range
Exit Sub
 
End If
 
Call Countup
 
End Sub

Sub Mail_Range()
'Working in 2000-2010
    Dim Source As Range
    Dim Dest As Workbook
    Dim wb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim I As Long
    Set Source = Nothing
    On Error Resume Next

    Set Source = Range("A1:B5").SpecialCells(xlCellTypeVisible)
       On Error GoTo 0
    If Source Is Nothing Then
        MsgBox "The source is not a range or the sheet is protected, " & _
               "please correct and try again.", vbOKOnly
     Exit Sub

    End If
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    Set wb = ActiveWorkbook
    Set Dest = Workbooks.Add(xlWBATWorksheet)
    Source.Copy
    With Dest.Sheets(1)
        .Cells(1).PasteSpecial Paste:=8
        .Cells(1).PasteSpecial Paste:=xlPasteValues
        .Cells(1).PasteSpecial Paste:=xlPasteFormats
        .Cells(1).Select
        Application.CutCopyMode = False
    End With
    TempFilePath = Environ$("temp") & "\"
    TempFileName = "Range of " & wb.Name & " " _
                 & Format(Now, "dd-mmm-yy h-mm-ss")
    If Val(Application.Version) < 12 Then
        'You use Excel 2000-2003
        FileExtStr = ".xls": FileFormatNum = -4143
    Else
        'You use Excel 2007-2010
        FileExtStr = ".xlsx": FileFormatNum = 51
    End If
    With Dest
        .SaveAs TempFilePath & TempFileName & FileExtStr, _
                FileFormat:=FileFormatNum
        On Error Resume Next
        For I = 1 To 3
            .SendMail "lhkittle@comcast.net", _
                      "This is the LHK TEST Subject line"
            If Err.Number = 0 Then Exit For
        Next I
        On Error GoTo 0
        .Close SaveChanges:=False
    End With
    'Delete the file you have send
    Kill TempFilePath & TempFileName & FileExtStr
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top