word vba - Adding attachment to mail merge to email -
i trying create mail merge email adds attachment. following procedure outlined in article http://word.mvps.org/faqs/mailmerge/mergewithattachments.html
the emails created , sent correct email addresses attachments not being added. have tested , correct file name being used.
sub emailmergewithattachments() dim source document, maillist document, tempdoc document dim datarange range dim long, j long dim bstarted boolean dim ooutlookapp outlook.application dim oitem outlook.mailitem dim mysubject string, message string, title string set source = activedocument ' check if outlook running. if not, start outlook on error resume next set ooutlookapp = getobject(, "outlook.application") if err <> 0 set ooutlookapp = createobject("outlook.application") bstarted = true end if ' open catalog mailmerge document dialogs(wddialogfileopen) .show end set maillist = activedocument ' show input box asking user subject inserted email messages message = "enter subject used each email message." ' set prompt. title = " email subject input" ' set title. ' display message, title mysubject = inputbox(message, title) ' iterate through sections of source document , rows of catalog mailmerge document, ' extracting information included in each email. j = 1 source.sections.count - 1 set oitem = ooutlookapp.createitem(olmailitem) oitem .subject = mysubject .body = source.sections(j).range.text set datarange = maillist.tables(1).cell(j, 1).range datarange.end = datarange.end - 1 .to = datarange = 2 maillist.tables(1).columns.count set datarange = maillist.tables(1).cell(j, i).range datarange.end = datarange.end - 1 .attachments.add trim(datarange.text), olbyvalue, 1 next .send end set oitem = nothing next j maillist.close wddonotsavechanges ' close outlook if started macro. if bstarted ooutlookapp.quit end if msgbox source.sections.count - 1 & " messages have been sent." 'clean set ooutlookapp = nothing end sub
most guessing problem
.attachments.add trim(datarange.text), olbyvalue, 1
is datarange.text equal full path file , file exist?
Comments
Post a Comment