Excel Macro Won't send e-mail when called from Access automatically

Sullivag2

New Member
Joined
Feb 25, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello every one. I am calling an Excel Macro from Access. I did extensive testing (I thought) last week with the Excel Macro. I did the step through and run to break points and every time the macro would send an e-mail with the attachments and the information it pulled from the one cell of the workbook. If it wasn't for needing that information from the cell for the total lines I could continue to send the e-mail from Access. When I run the access database it will call the macro and format the sheet but it never sends the e-mail unless I already have the Excel macro open and then again walk through or run to a break point and then continue. I get no error messages either when it doesn't work. Any help would be appreciated. I added the loop function to try and give it more time to be able to send the e-mail thinking that maybe it was processing too fast for some reason.


Public Function EmailReport(totalcount)
Dim OutApp As Object
Dim OutMail As Object
Dim strFileName As String
Dim MyDate
Dim Response
Dim DayNumber As Integer
Dim test As Integer
Dim strChartFileName As String
Dim strDetailFileName As String
Dim i As Integer





MyDate = Month(Date) & Day(Date) & Year(Date)







strChartFileName = "C:\Supplier Responsiveness Reports\Supplier Responsiveness Chart " & MyDate & ".xlsx"
strDetailFileName = "C:\Supplier Responsiveness Reports\Supplier Responsiveness Details " & MyDate & ".xlsx"




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

On Error Resume Next
With OutMail
.to = myaddress@server.com (changed to hide)
.CC = ""
.BCC = ""
.Subject = "Supplier Responsiveness Report " & Date
.Body = "Hello Everyone! " & vbNewLine & vbNewLine & "The attached weekly reports look at the PO's that are late to the Planned/Next Need Date." & vbNewLine _
& "The overall count is " & totalcount & " lines" & vbNewLine & "Currently on this file we are showing all suppliers." & vbNewLine _
& "The Detail file is sorted by IM Buyer; Supplier: PO and Position." & vbNewLine & "The Chart file is sorted by Buyer # and then Supllier #. " _
& vbNewLine & vbNewLine _
& "Gary C Sullivan II" & vbNewLine & "Order Fullfillment Analyst" & vbNewLine & "Manitowoc Crane Care" & vbNewLine & & vbNewLine _
& "Integrity Commitment to Stakeholders, and Passion for Excellence"


.attachments.Add strChartFileName
.attachments.Add strDetailFileName


.Send 'or use .Display
End With
On Error GoTo 0


'Trying to give Excel time to process before closing ang going back to Access

i = 1
Do While i < 250
i = i + 1

Loop

Set OutMail = Nothing
Set OutApp = Nothing



End Function
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

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