Mystery: Filled Excel sheet is blank when attached to an email

Godot60

Board Regular
Joined
May 11, 2017
Messages
62
Hi all,

I'm hoping you can help me solve a mystery. I have a button on a form that sends the sheet as an email attachment once it has been completed. The problem is that the email when received is blank and what had been filled out is no longer there. The code appears below. Any clues? Thanks.

Sub Mail_small_Text_Outlook()If Range("f8").Value = "" Or Range("f10").Value = "" Or Range("a29").Value = "" Or Range("j10").Value = "" Or Range("f12").Value = "" Or Range("f14").Value = "" Or Range("k14").Value = "" Or Range("f16").Value = "" Or Range("k16").Value = "" Or Range("H25").Value = "" Or Range("f18").Value = "" Then
MsgBox "Please complete all required fields"
Exit Sub
End If
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "To be extended: " & Sheet1.Range("j10") & vbNewLine & _
"Department: " & Sheet1.Range("f12") & vbNewLine & _
"Classification: " & Sheet1.Range("f18") & vbNewLine & _
"Extension details: " & Sheet1.Range("f20") & vbNewLine & _
"Requestor: " & Sheet1.Range("f14")
On Error Resume Next
With OutMail
.To = "roco@lsre.edu"
.CC = ""
.BCC = ""
.Subject = "Request for extension: " & Sheet1.Range("j10")
.Body = strbody
.Display
.Attachments.Add ActiveWorkbook.FullName
'You can add a file like this
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try adding "ActiveWorkbook.Save" before adding the attachment. The problem might be that it is attaching the entire workbook from the last saved point.
 
Upvote 0
.
You have 2 .Display commands. I deleted the first one, then edited your macro concerning the .Attachment.Add

Code:
Option Explicit


Sub Mail_small_Text_Outlook()
    If Range("f8").Value = "" Or Range("f10").Value = "" Or Range("a29").Value = "" Or Range("j10").Value = "" Or Range("f12").Value = "" Or Range("f14").Value = "" Or Range("k14").Value = "" Or Range("f16").Value = "" Or Range("k16").Value = "" Or Range("H25").Value = "" Or Range("f18").Value = "" Then
        MsgBox "Please complete all required fields"
        Exit Sub
    End If


Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String


Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)


strbody = "To be extended: " & Sheet1.Range("j10") & vbNewLine & _
"Department: " & Sheet1.Range("f12") & vbNewLine & _
"Classification: " & Sheet1.Range("f18") & vbNewLine & _
"Extension details: " & Sheet1.Range("f20") & vbNewLine & _
"Requestor: " & Sheet1.Range("f14")


On Error Resume Next


    With OutMail
        .To = "mymail@lsre.edu"
        .CC = ""
        .BCC = ""
        .Subject = "Request for extension: " & Sheet1.Range("j10")
        .Body = strbody
        
        '.Attachments.Add ActiveWorkbook.FullName
        .Attachments.Add Application.ActiveWorkbook.FullName
        
        'You can add a file like this
        '.Attachments.Add ("C:\test.txt")
        '.Send 'or use .Display
    .Display
    End With


On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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