Need to send Outlook E-mail from Excel VBA without warnings.

P

Prz59

I'm trying to automate the sending of a spreadsheet from via Outlook. I have
the code in place to build the spreadsheet and setup the Outlook Application
object and the MailItem object. It sends the message but gives me a warning
that requires a user interaction. Is there a way to bypass this warning?
 
C

chijanzen

Hi,Prz59

Display Month

Public Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long,
ByVal lpTimerfunc As Long) As Long
Public Declare Function KillTimer Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Function WinProcA(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As
Long, ByVal SysTime As Long) As Long
KillTimer 0, idEvent
DoEvents
Sleep 100
' Alt + s send mail
Application.SendKeys "%s"
End Function
Sub SendMail()
Dim objOL As Object
Dim itmNewMail As Object
'Microsoft Outlook object
Set objOL = CreateObject("Outlook.Application")
Set itmNewMail = objOL.CreateItem(olMailItem)
With itmNewMail
.Subject = "chijanzen Mail Test" 'Subject
.Body = Application.UserName & "Email test" 'Body
.To = "(e-mail address removed)" 'User
.Attachments.Add ThisWorkbook.FullName 'send ThisWorkbook
.Display 'Display
SetTimer 0, 0, 0, AddressOf WinProcA
End With
Set objOL = Nothing
Set itmNewMail = Nothing
End Sub
 
P

Prz59

It's not working. It displays the message with the attachment, but never
sends it.

I had to create the WinProcA Function in a module outside the WorkBook code
for it to run using the AddressOf operator. It doesn't appear to go into that
function when I step through the code in the de-bugger.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top