Help with DeBruin Email script

chefdt

Board Regular
Joined
Jul 1, 2008
Messages
163
I have tried using the code with no success. My screen flashes, no errors, nothing...also no email. What am I doing wrong?

I have a workbook with multiple sheets, with the address in A1, just as described in his code.

DT
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Why don't you post the code that you are trying, so that we may have a fighting chance to figure out what is going on...
 
Upvote 0
Sorry, I though everyone is familiar with his code. Whenever I ask a question about email, this is the code people send me.

Code:
[COLOR=#3366CC]Sub Mail_Every_Worksheet()[/COLOR][COLOR=black]'Working in Excel 2000-2013
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm[/COLOR]
    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
        [COLOR=black]'You use Excel 97-2003[/COLOR]
        FileExtStr = ".xls": FileFormatNum = -4143
    Else
        [COLOR=black]'You use Excel 2007-2013[/COLOR]
        FileExtStr = ".xlsm": FileFormatNum = 52
    End If

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    Set OutApp = CreateObject("Outlook.Application")

    For Each sh In ThisWorkbook.Worksheets
        If sh.Range("A1").Value Like "?*@?*.?*" Then

            sh.Copy
            Set wb = ActiveWorkbook

            TempFileName = "Sheet " & sh.Name & " of " _
                         & ThisWorkbook.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")

            Set OutMail = OutApp.CreateItem(0)

            With wb
                .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum

                On Error Resume Next
                With OutMail
                    .to = sh.Range("A1").Value
                    .CC = ""
                    .BCC = ""
                    .Subject = "This is the Subject line"
                    .Body = "Hi there"
                    .Attachments.Add wb.FullName
                    [COLOR=black]'You can add other files also like this
                    '.Attachments.Add ("C:\test.txt")[/COLOR]
                    .Send   [COLOR=black]'or use .Display[/COLOR]
                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 [COLOR=#3366CC]End Sub[/COLOR]
 
Upvote 0
Here is the thing, I am familiar with the code, however his code works and yours does not, so what good does it do me to read his code which works. I want to see (unless this is it verbatim) what you have on your sheet AKA "the code with no sucess". Does that make any sense...
 
Upvote 0
And do you really have:

Code:
With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With [COLOR=#3366CC]End Sub[/COLOR]

"End With" and "End Sub" on the same line and you don't get a compile error...
 
Upvote 0
I have used and improved on Ron DeBruin's code, but only for CDO. I have not used Outlook, but if you can post what line it fails on while debugging and any errors seen, I can help. Odds are that it is something simple.
 
Upvote 0
I have used and improved on Ron DeBruin's code, but only for CDO. I have not used Outlook, but if you can post what line it fails on while debugging and any errors seen, I can help. Odds are that it is something simple.

Oh... I'm also using 2013 (365). Is that a problem possibly?
 
Upvote 0
I have used and improved on Ron DeBruin's code, but only for CDO. I have not used Outlook, but if you can post what line it fails on while debugging and any errors seen, I can help. Odds are that it is something simple.

That's just it. It runs Error Free....Just doesnt send the email.
 
Upvote 0
And do you really have:



"End With" and "End Sub" on the same line and you don't get a compile error...

Code:
[COLOR=#3366CC]Sub Mail_Every_Worksheet()[/COLOR][COLOR=black]'Working in Excel 2000-2013
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm[/COLOR]
    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
        [COLOR=black]'You use Excel 97-2003[/COLOR]
        FileExtStr = ".xls": FileFormatNum = -4143
    Else
        [COLOR=black]'You use Excel 2007-2013[/COLOR]
        FileExtStr = ".xlsm": FileFormatNum = 52
    End If

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    Set OutApp = CreateObject("Outlook.Application")

    For Each sh In ThisWorkbook.Worksheets
        If sh.Range("A1").Value Like "?*@?*.?*" Then

            sh.Copy
            Set wb = ActiveWorkbook

            TempFileName = "Sheet " & sh.Name & " of " _
                         & ThisWorkbook.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")

            Set OutMail = OutApp.CreateItem(0)

            With wb
                .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum

                On Error Resume Next
                With OutMail
                    .to = sh.Range("A1").Value
                    .CC = ""
                    .BCC = ""
                    .Subject = "This is the Subject line"
                    .Body = "Hi there"
                    .Attachments.Add wb.FullName
                    [COLOR=black]'You can add other files also like this
                    '.Attachments.Add ("C:\test.txt")[/COLOR]
                    .Send   [COLOR=black]'or use .Display[/COLOR]
                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 
[COLOR=#3366CC]End Sub[/COLOR]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,530
Messages
6,114,163
Members
448,554
Latest member
Gleisner2

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