vba - Wrong number of arguments when sending Email with AutoExec -


i'm trying send email through function downloaded c.pearson. when try make work error: "the expression entered has function containing wrong number of arguments."

here's code i'm using:

option explicit option compare text  function sendemail(subject string, _         fromaddress string, _         toaddress string, _         mailbody string, _         smtp_server string, _         optional bodyfilename string, _         optional attachments variant = empty) boolean  dim mailmessage cdo.message dim n long dim fnum integer dim s string dim body string dim recips() string dim recip string dim nrecip long  ' ensure required parameters present , valid. if len(trim(subject)) = 0     sendemail = false     exit function end if  if len(trim(fromaddress)) = 0     sendemail = false     exit function end if  if len(trim(smtp_server)) = 0     sendemail = false     exit function end if  ' clean addresses recip = replace(toaddress, space(1), vbnullstring) recips = split(recip, ";")  nrecip = lbound(recips) ubound(recips)     on error resume next     ' create cdo message object.     set mailmessage = createobject("cdo.message")     if err.number <> 0         sendemail = false         exit function     end if     err.clear     on error goto 0     mailmessage         .subject = subject         .from = fromaddress         .to = recips(nrecip)         if mailbody <> vbnullstring             .textbody = mailbody         else             if bodyfilename <> vbnullstring                 if dir(bodyfilename, vbnormal) <> vbnullstring                     ' import text of body file bodyfilename                     fnum = freefile                     s = vbnullstring                     body = vbnullstring                     open bodyfilename input access read #fnum                     until eof(fnum)                         line input #fnum, s                         body = body & vbnewline & s                     loop                     close #fnum                     .textbody = body                 else                     ' bodyfilename not found.                     sendemail = false                     exit function                 end if             end if ' mailbody , bodyfilename both vbnullstring.         end if          if isarray(attachments) = true             ' attach files in array.             n = lbound(attachments) ubound(attachments)                 ' ensure attachment file exists , attach it.                 if attachments(n) <> vbnullstring                     if dir(attachments(n), vbnormal) <> vbnullstring                         .addattachment attachments(n)                     end if                 end if             next n         else             ' ensure file exists , if so, attach message.             if attachments <> vbnullstring                 if dir(cstr(attachments), vbnormal) <> vbnullstring                     .addattachment attachments                 end if             end if         end if         .configuration.fields             ' set smtp configuration             .item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2             .item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtp_server             .item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25             .update         end          on error resume next         err.clear         ' send message         .send         if err.number = 0             sendemail = true         else             sendemail = false             exit function         end if     end next nrecip  end function   public sub emailsendsub() sendemail ("my email", "spetsnaz307@gmail.com", "spetsnaz307@hotmail.co.nz","hello", smtp_server:="smtp.gmail.com", "d:\other\modemail.bas", attachments:=empty)  end sub 

i have macro named 'autoexec', , code in module called 'modemail'.

my macro's action runcode , function name is: 'sendemail()'

how can fix error? i've been playing around code days , can't seem come solution.

note: my port 25 blocked isp, cause particular error?

thanks in advance help. :)

as can see function declaration in vba code, function expects supply subject line, fromaddress, toaddress, etc., arguments. if macro calling sendemail() (without arguments) problem because you're not telling function send, or whom.

the function call needs more like

sendemail("this subject", "sender@example.com", "recipient@example.com", ... 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -