Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Macro to Send Mail on Trigger doesnt work

Hi everbody,

the following macro doesnt work with trigger onpostreload, if I start the reload with a cmd Batch file which uses the /r command. If it uses the /l command it works fine. Can someone tell me why?

sub SendMail 
set Report=ActiveDocument.GetSheetObject("CH86") 

var_emailRecipients = "mailaddresses"


txtBody="<HTML><BODY> <font face=""verdana"" size=""2""> Report <br>" 
txtBody=txtBody &"<font face=""verdana"" size=""2""> Report1<font>"

txtBody=txtBody & "<TABLE border=""1"">" 

For i=0 to Report.GetRowCount-1 
txtBody=txtBody&"<TR>"

For d=0 to Report.GetColumnCount-1

txtBody=txtBody&"<Td><font face=""verdana"" size=""2"">" 
txtBody=txtBody&Report.GetCell(i,d).text 
txtBody=txtBody&" </font></Td>"

Next
txtBody=txtBody&"</TR>"

Next


txtBody=txtBody&"</TABLE>"


txtBody=txtBody&"</BODY></HTML>" 


Set gObjExcel=Nothing 
Set objMsg = CreateObject("CDO.Message") 
Set msgConf = CreateObject("CDO.Configuration") 

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = number  
msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "server" 
msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = number
msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = number  
msgConf.Fields.Update 

objMsg.Subject = "Report " 
objMsg.To = var_emailRecipients 
objMsg.From = "Sender" 

objMsg.HTMLBody =txtBody 

Set objMsg.Configuration = msgConf 
objMsg.Send 


Set objMsg = nothing 
Set msgConf = nothing 
 
end sub 

Thank you in advance.

3 Replies
marcus_sommer

Maybe this is helpful for you: Re: Sending mails macro vbs.

- Marcus

Anonymous
Not applicable
Author

I already set the Requested Module Security to System Access und the Current Local Security to Allow System Access. That should be correct.

But your answer in the mentioned topic

I have the same problem had. Problem seems to be that that CDO.Message requires run with priority and not as background process.

could be possible.

cwolf
Creator III
Creator III

The option /r does not call any trigger. You have to use /l with saving the document and closing the application inside the macro:

sub SendMail

    ActiveDocument.Save

    ActiveDocument.GetApplication.WaitForIdle

    // Your code ...

    ActiveDocument.GetApplication.WaitForIdle

    ActiveDocument.GetApplication.Quit

end sub

- Christian