Attach both pdf and excel files to an email on single click in VBA -



Attach both pdf and excel files to an email on single click in VBA -

i have vba code create pdf file in excel , attache email on button click. wondering if possible attach both pdf , excel file email on single click. please find below code trying modify.. bold section showing 2 functions. suggestion or help appreciated !!

sub button1_click() dim emailsubject string, emailsignature string dim email_body string dim olmailitem object 'dim olformathtml form dim objmail object dim currentmonth string, destfolder string, pdffile string dim email_to string, email_cc string, email_bcc string dim openpdfaftercreating boolean, alwaysoverwritepdf boolean, displayemail boolean dim overwritepdf vbmsgboxresult dim outlookapp object, outlookmail object 'currentmonth = "" dim fname string, ecode1 string, ecode2 string, fnamelong string ' ***************************************************** ' ***** can alter these variables ********* 'create excel fname = "user access request:" ecode1 = sheet1.range("b7").value ecode2 = range("b7").value fnamelong = fname & " " & ecode1 & " - " & ecode2 emailsubject = "abs" 'change alter subject of email. current month added end of subj line openpdfaftercreating = false 'change if want open pdf after creating : true or false alwaysoverwritepdf = true 'change if want overwrite pdf exists :true or false displayemail = true 'change if don't want display email before sending. note, must have email address specified work email_to = "abc" 'change if want specify email e.g. activesheet.range("h1") email cell h1 email_cc = "xyz.com" email_bcc = "" 'create pdf activesheet.exportasfixedformat type:=xltypepdf, filename:=pdffile, quality:=xlqualitystandard, includedocproperties:=true, ignoreprintareas _ :=false, openafterpublish:=openpdfaftercreating ** 'create outlook object , new mail service message set outlookapp = createobject("outlook.application") 'dialogs (dialogsendmail).show ") set outlookmail = outlookapp.createitem(0) 'create excel file email application.dialogs(xldialogsendmail).show "xyz", fnamelong ** 'display email , specify to, subject, etc outlookmail .display .to = email_to .cc = email_cc .bcc = email_bcc .subject = emailsubject & currentmonth .attachments.add pdffile if displayemail = false .send end if end end sub

with outlookmail .display .to = email_to .cc = email_cc .bcc = email_bcc .subject = emailsubject & currentmonth .attachments.add pdffile .attachments.add "[excel file path goes here]" 'add line if displayemail = false .send end if end

vba

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -