MailEnvelope problem

liampog

Active Member
Joined
Aug 3, 2010
Messages
308
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi

I have some code (below) that I use to send a Named Range via the MailEnvelope function of Excel.

It was working for a while but now, when I run the macro to send the e-mail, everything works up to .Send. There are no crashes or error messages but it doesn't send. Before, you would see the e-mail appear in the Outbox and then it would be Sent. Now, it just bypasses that line in the code, continues but doesn't send.

Can anyone figure out what's going wrong?

I'm using Windows 10 and Office 365 (Outlook and Excel).

I can't for the life of me understand why it's worked previously and isn't anymore.

Code:
Sub InterimReport_Send()
    If ActiveSheet.Name = "Report" Then        
        ThisWorkbook.Save        
        Dim PreviousSelection As Range    
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
            .DisplayAlerts = False
        End With        
        Set PreviousSelection = ActiveCell        
        ActiveSheet.Unprotect Password:="Report"        
        Range("Report_InsideBorders").Borders(xlInsideHorizontal).Weight = xlMedium        
        ActiveSheet.Protect Password:="Report"
        On Error GoTo StopSend        
        Range("Report_MailRange").Select        
        ActiveWorkbook.EnvelopeVisible = True
        With ActiveSheet.MailEnvelope.Item                                
            .To = "email@address.com"            
            .Subject = "Subject"            
            .Send        
        End With        
        ActiveWorkbook.EnvelopeVisible = False    
StopSend:        
        ActiveSheet.Unprotect Password:="Report"
        Range("Report_InsideBorders").Borders(xlInsideHorizontal).Weight = xlThin
        ActiveSheet.Protect Password:="Report"    
        PreviousSelection.Select    
        With Application            
            .DisplayAlerts = True        
            .ScreenUpdating = True            
            .EnableEvents = True            
        End With    
    End If
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
First, comment out or delete this line...

Code:
On Error GoTo StopSend

Then try running your macro again. Do you get an error? If so, which one and on which line?
 
Upvote 0
Hi

Sorry I should have mentioned I have tried this :(

It doesn’t stop on any line with any error messages. I’ve even done it step by step and it gets to that line .Send and just moves on to the next line.
 
Upvote 0
When .Send is executed, the email should only appear in Outbox for a few seconds, assuming all goes well, until it's actually sent. So the email should appear in your Sent folder. Is it not there in your Sent folder?
 
Upvote 0
When .Send is executed, the email should only appear in Outbox for a few seconds, assuming all goes well, until it's actually sent. So the email should appear in your Sent folder. Is it not there in your Sent folder?

Hi Domenic

Yes I understand that and I've seen it happen where it's there momentarily, however, it's not even going to the Outbox for that split second and is definitely not being Sent.

:(

It's frustrating because it was working but I don't believe there has been any significant change that has caused it to stop.

Thanks
Liam
 
Upvote 0
You've unprotected your sheet to apply your borders, but then you protect it again before sending your email. Try protecting it again only after you've sent your email. Does this help?
 
Upvote 0
Haha

So interestingly, I had a different problem before this one whereby the line protecting the sheet BEFORE attempting to send was causing Outlook and Excel to both crash to the point where you can only force close them via Task Manager.

Adding the FIRST line of reprotection SOLVED the crashing issue but then seemed to stop .Send from working.

Before ALL of this however, the whole sheet was working without any issues at all.

Completely at a loss....
 
Upvote 0
Sorry, it's not clear to me whether you tried it. Did you try it? And, if so, was it successful?
 
Upvote 0
Sorry I think my point was missed, being that prior to THIS specific problem, the line of protecting the sheet after setting the borders wasn’t present. The sheet was unprotected before applying the borders and reprotected after the borders are reset later on.

This would crash Excel and Outlook.
 
Upvote 0

Forum statistics

Threads
1,214,790
Messages
6,121,608
Members
449,038
Latest member
apwr

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