SOLVED
Home

vba sending email w/ attachment

%3CLINGO-SUB%20id%3D%22lingo-sub-389059%22%20slang%3D%22en-US%22%3Evba%20sending%20email%20w%2F%20attachment%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-389059%22%20slang%3D%22en-US%22%3E%3CP%3Elong%20bit%20of%20code%20and%20im%20sure%20you%20all%20don't%20need%20all%20of%20it%20but%20its%20here%20for%20reference.%20The%20email%20portion%20works%20fine%20when%20under%20strBody%20i%20have%20text%20or%20a%20range%20with%20%22%22.%20the%20problem%20im%20having%20is%20with%20getting%20it%20to%20upload%20a%20file%20path%20for%20an%20attachment.%20do%20i%20have%20to%20change%20all%20my%20code%20or%20is%20there%20just%20a%20slight%20typo.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethe%20WBname%20portion%20of%20it%20is%20a%20public%20variable%20defined%20in%20a%20different%20module%20and%20works%20like%20it%20should%20within%20its%20own%20module%20(the%20following%20module).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOption%20Explicit%3CBR%20%2F%3EPublic%20Sub%20BlkLst_Save()%3C%2FP%3E%3CP%3EPublic%20WBname%20As%20String%3CBR%20%2F%3EWBname%20%3D%20%22BlackList%22%20%26amp%3B%20ActiveSheet.Name%20%26amp%3B%20Format(Now()%2C%20%22MMM%20dd%2C%20yyyy%22)%3C%2FP%3E%3CP%3EWorkbooks.Add%3CBR%20%2F%3EActiveWorkbook.SaveAs%20Filename%3A%3DWBname%3C%2FP%3E%3CP%3EWorkbooks(%22blacklist%20system%22).Activate%3CBR%20%2F%3ERange(%22A1%3AF150%22).Select%3CBR%20%2F%3ESelection.Copy%3C%2FP%3E%3CP%3EWorkbooks(WBname).Activate%3CBR%20%2F%3ERange(%22A1%22).Select%3CBR%20%2F%3EActiveSheet.Paste%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eso%20the%20above%20works%20fine.%20Below%20is%20the%20email%20portion%20of%20this%20and%20runs%20into%20an%20error%20when%20trying%20to%20pull%20from%20that%20save%20path%20as%20previously%20stated.%20I%20have%20bolded%20and%20italicized%20the%20portion%20that%20errors%20out.%20(****%20indicate%20deleted%20information%20for%20security)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPublic%20Sub%20M_Emailer()%3CBR%20%2F%3E'sends%20email%20to%20Marik%20for%20blacklisted%20devices%3C%2FP%3E%3CP%3EDim%20CDO_Mail%20As%20Object%3CBR%20%2F%3EDim%20CDO_Config%20As%20Object%3CBR%20%2F%3EDim%20SMTP_Config%20As%20Variant%3CBR%20%2F%3EDim%20strSubject%20As%20String%3CBR%20%2F%3EDim%20strFrom%20As%20String%3CBR%20%2F%3EDim%20strTo%20As%20String%3CBR%20%2F%3EDim%20strCc%20As%20String%3CBR%20%2F%3EDim%20strBcc%20As%20String%3CBR%20%2F%3EDim%20strBody%20As%20String%3C%2FP%3E%3CP%3EstrSubject%20%3D%20%22Blacklist%20From%20CDR%22%3CBR%20%2F%3EstrFrom%20%3D%20%22*******%22%3CBR%20%2F%3EstrTo%20%3D%20%22********%22%3CBR%20%2F%3EstrCc%20%3D%20%22%22%3CBR%20%2F%3EstrBcc%20%3D%20%22%22%3CBR%20%2F%3EstrBody%20%3D%20%3CSTRONG%3E%3CEM%3EC%3A%5CUsers%5Ctabor%5CDocuments%5C%26amp%3BWBname%26amp%3B.xlsx%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESet%20CDO_Mail%20%3D%20CreateObject(%22CDO.Message%22)%3CBR%20%2F%3EOn%20Error%20GoTo%20Error_Handling%3C%2FP%3E%3CP%3ESet%20CDO_Config%20%3D%20CreateObject(%22CDO.Configuration%22)%3CBR%20%2F%3ECDO_Config.Load%20-1%3C%2FP%3E%3CP%3ESet%20SMTP_Config%20%3D%20CDO_Config.Fields%3C%2FP%3E%3CP%3EWith%20SMTP_Config%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendusing%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendusing%3C%2FA%3E%22)%20%3D%202%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpserver%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpserver%3C%2FA%3E%22)%20%3D%20%22smtp.gmail.com%22%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpauthenticate%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpauthenticate%3C%2FA%3E%22)%20%3D%201%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendusername%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendusername%3C%2FA%3E%22)%20%3D%20%22*******%22%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendpassword%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendpassword%3C%2FA%3E%22)%20%3D%20%22*******%22%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpserverport%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpserverport%3C%2FA%3E%22)%20%3D%20465%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpusessl%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpusessl%3C%2FA%3E%22)%20%3D%201%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpconnectiontimeout%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpconnectiontimeout%3C%2FA%3E%22)%20%3D%2060%3CBR%20%2F%3E.Update%3CBR%20%2F%3EEnd%20With%3C%2FP%3E%3CP%3EWith%20CDO_Mail%3CBR%20%2F%3ESet%20.Configuration%20%3D%20CDO_Config%3CBR%20%2F%3EEnd%20With%3C%2FP%3E%3CP%3ECDO_Mail.Subject%20%3D%20strSubject%3CBR%20%2F%3ECDO_Mail.From%20%3D%20strFrom%3CBR%20%2F%3ECDO_Mail.To%20%3D%20strTo%3CBR%20%2F%3ECDO_Mail.TextBody%20%3D%20strBody%3CBR%20%2F%3ECDO_Mail.CC%20%3D%20strCc%3CBR%20%2F%3ECDO_Mail.BCC%20%3D%20strBcc%3CBR%20%2F%3ECDO_Mail.Send%3C%2FP%3E%3CP%3EError_Handling%3A%3CBR%20%2F%3EIf%20Err.Description%20%26lt%3B%26gt%3B%20%22%22%20Then%20MsgBox%20Err.Description%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-389059%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EVba%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-390149%22%20slang%3D%22en-US%22%3ERe%3A%20vba%20sending%20email%20w%2F%20attachment%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-390149%22%20slang%3D%22en-US%22%3EExcellent%2C%20thanks%20for%20letting%20us%20know.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-390125%22%20slang%3D%22en-US%22%3ERe%3A%20vba%20sending%20email%20w%2F%20attachment%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-390125%22%20slang%3D%22en-US%22%3E%3CP%3Eno%20sure%20if%20i%20typed%20something%20in%20wrong%20before%20or%20what%20but%20now%20its%20working%3F%3F%3F%26nbsp%3B%20thx%20for%20the%20help%20guys!%20took%20out%20all%20my%20other%20code%20that%20pertained%20to%20trying%20and%20uploading%20an%20attachment%20and%20just%20added%20this%20one%20piece%20at%20the%20bottom%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECDO_Mail.Subject%20%3D%20strSubject%3CBR%20%2F%3ECDO_Mail.From%20%3D%20strFrom%3CBR%20%2F%3ECDO_Mail.To%20%3D%20strTo%3CBR%20%2F%3ECDO_Mail.TextBody%20%3D%20strBody%3CBR%20%2F%3ECDO_Mail.AddAttachment%20%22C%3A%5CUsers%5Ctabor%5CDocuments%5C%22%20%26amp%3B%20WBname%20%26amp%3B%20%22.xlsx%22%3CBR%20%2F%3ECDO_Mail.CC%20%3D%20strCc%3CBR%20%2F%3ECDO_Mail.BCC%20%3D%20strBcc%3CBR%20%2F%3ECDO_Mail.Send%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethought%20i%20had%20already%20tried%20that%20and%20it%20wasn't%20working.%20Not%20going%20to%20mess%20with%20it%20anymore%20that's%20for%20sure%20lol.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-389796%22%20slang%3D%22en-US%22%3ERe%3A%20vba%20sending%20email%20w%2F%20attachment%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-389796%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EMessage%20object%20is%20not%20have%20a%20Attachment%20property.%3CBR%20%2F%3Ethere%20is%20an%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fprevious-versions%2Fexchange-server%2Fexchange-10%2Fms528117%2528v%253dexchg.10%2529%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAttachments%3C%2FA%3E%20property%2C%20but%20it%20is%20read%20only.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUse%20the%20AddAttachment%20method%20when%20you%20want%20to%20attach%20a%20file.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdevblogs.microsoft.com%2Fscripting%2Fhow-can-i-attach-a-file-to-an-email-sent-using-cdo%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdevblogs.microsoft.com%2Fscripting%2Fhow-can-i-attach-a-file-to-an-email-sent-using-cdo%2F%3C%2FA%3E%3C%2FP%3E%3CP%3E%3CBR%20%2F%3ERegards%2C%3CBR%20%2F%3Ekinuasa%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-389657%22%20slang%3D%22en-US%22%3ERe%3A%20vba%20sending%20email%20w%2F%20attachment%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-389657%22%20slang%3D%22en-US%22%3E%3CP%3Eso%20heres%20what%20i%20have%20now.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPublic%20Sub%20M_Emailer()%3CBR%20%2F%3E'creates%20the%20save%20file%20to%20send%3CBR%20%2F%3EDim%20WBname%20As%20String%3CBR%20%2F%3EWBname%20%3D%20%22BlackList%22%20%26amp%3B%20ActiveSheet.Name%20%26amp%3B%20Format(Now()%2C%20%22MMM%20dd%2C%20yyyy%22)%3C%2FP%3E%3CP%3EWorkbooks.Add%3CBR%20%2F%3EActiveWorkbook.SaveAs%20Filename%3A%3DWBname%3C%2FP%3E%3CP%3EWorkbooks(%22blacklist%20system%22).Activate%3CBR%20%2F%3ERange(%22A1%3AF150%22).Select%3CBR%20%2F%3ESelection.Copy%3C%2FP%3E%3CP%3EWorkbooks(WBname).Activate%3CBR%20%2F%3ERange(%22A1%22).Select%3CBR%20%2F%3EActiveSheet.Paste%3CBR%20%2F%3E'sends%20email%20to%20Marik%20for%20blacklisted%20devices%3CBR%20%2F%3EDim%20CDO_Mail%20As%20Object%3CBR%20%2F%3EDim%20CDO_Config%20As%20Object%3CBR%20%2F%3EDim%20SMTP_Config%20As%20Variant%3CBR%20%2F%3EDim%20strSubject%20As%20String%3CBR%20%2F%3EDim%20strFrom%20As%20String%3CBR%20%2F%3EDim%20strTo%20As%20String%3CBR%20%2F%3EDim%20strCc%20As%20String%3CBR%20%2F%3EDim%20strBcc%20As%20String%3CBR%20%2F%3EDim%20strBody%20As%20String%3CBR%20%2F%3E%3CSTRONG%3EDim%20strAtch%20As%20String%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EstrSubject%20%3D%20%22Blacklist%20From%20CDR%22%3CBR%20%2F%3EstrFrom%20%3D%20%22email%22%3CBR%20%2F%3EstrTo%20%3D%20%22email%22%3CBR%20%2F%3EstrCc%20%3D%20%22%22%3CBR%20%2F%3EstrBcc%20%3D%20%22%22%3CBR%20%2F%3EstrBody%20%3D%20WBname%3CBR%20%2F%3E%3CSTRONG%3EstrAtch%20%3D%20%22C%3A%5CUsers%5Ctabor%5CDocuments%5C%22%20%26amp%3B%20WBname%20%26amp%3B%20%22.xlsx%22%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3ESet%20CDO_Mail%20%3D%20CreateObject(%22CDO.Message%22)%3CBR%20%2F%3EOn%20Error%20GoTo%20Error_Handling%3C%2FP%3E%3CP%3ESet%20CDO_Config%20%3D%20CreateObject(%22CDO.Configuration%22)%3CBR%20%2F%3ECDO_Config.Load%20-1%3C%2FP%3E%3CP%3ESet%20SMTP_Config%20%3D%20CDO_Config.Fields%3C%2FP%3E%3CP%3EWith%20SMTP_Config%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendusing%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendusing%3C%2FA%3E%22)%20%3D%202%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpserver%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpserver%3C%2FA%3E%22)%20%3D%20%22smtp.gmail.com%22%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpauthenticate%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpauthenticate%3C%2FA%3E%22)%20%3D%201%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendusername%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendusername%3C%2FA%3E%22)%20%3D%20%22email%22%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendpassword%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendpassword%3C%2FA%3E%22)%20%3D%20%22pass%22%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpserverport%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpserverport%3C%2FA%3E%22)%20%3D%20465%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpusessl%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpusessl%3C%2FA%3E%22)%20%3D%201%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpconnectiontimeout%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpconnectiontimeout%3C%2FA%3E%22)%20%3D%2060%3CBR%20%2F%3E.Update%3CBR%20%2F%3EEnd%20With%3C%2FP%3E%3CP%3EWith%20CDO_Mail%3CBR%20%2F%3ESet%20.Configuration%20%3D%20CDO_Config%3CBR%20%2F%3EEnd%20With%3C%2FP%3E%3CP%3ECDO_Mail.Subject%20%3D%20strSubject%3CBR%20%2F%3ECDO_Mail.From%20%3D%20strFrom%3CBR%20%2F%3ECDO_Mail.To%20%3D%20strTo%3CBR%20%2F%3ECDO_Mail.TextBody%20%3D%20strBody%3CBR%20%2F%3E%3CSTRONG%3ECDO_Mail.Attachment%20%3D%20strAtch%3C%2FSTRONG%3E%3CBR%20%2F%3ECDO_Mail.CC%20%3D%20strCc%3CBR%20%2F%3ECDO_Mail.BCC%20%3D%20strBcc%3CBR%20%2F%3ECDO_Mail.Send%3C%2FP%3E%3CP%3EError_Handling%3A%3CBR%20%2F%3EIf%20Err.Description%20%26lt%3B%26gt%3B%20%22%22%20Then%20MsgBox%20Err.Description%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Enow%20i%20get%20%22object%20doesn't%20support%20this%20property%20or%20method%22%20when%20it%20gets%20to%20the%26nbsp%3B%3CSTRONG%3ECDO_Mail.Attachment%20%3D%20strAtch%20line%26nbsp%3B%3C%2FSTRONG%3E%3F%20most%20of%20the%20articles%20im%20looking%20at%20utilize%20outlook%20and%20not%20CDO.%20The%20link%20you%20posted%20was%20one%20article%20i've%20gone%20over%20and%20even%20downloaded%20his%20modules%20to%20go%20through%20them%20and%20try%20to%20decode%20them%20but%20what%20he%20has%20written%20down%20isn't%20notated%20very%20well%20to%20where%20someone%20as%20inexperienced%20as%20i%20can%20understand%20whats%20going%20on.%20all%20this%20is%20way%20over%20my%20head%20and%20why%20im%20asking%20for%20help.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-389541%22%20slang%3D%22en-US%22%3ERe%3A%20vba%20sending%20email%20w%2F%20attachment%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-389541%22%20slang%3D%22en-US%22%3EPerhaps%20you%20can%20find%20what%20you%20need%20here%3A%20%3CA%20href%3D%22http%3A%2F%2Frondebruin.nl%2Fwin%2Fs1%2Fcdo.htm%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Frondebruin.nl%2Fwin%2Fs1%2Fcdo.htm%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-389509%22%20slang%3D%22en-US%22%3ERe%3A%20vba%20sending%20email%20w%2F%20attachment%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-389509%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F22322%22%20target%3D%22_blank%22%3E%40Jan%20Karel%20Pieterse%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20can't%20seem%20to%20figure%20out%20how%20this%20one%20works.%20i%20tried%20to%20just%20copy%20and%20paste%20what%20you%20put%20with%20no%20success.%20Looked%20up%20quite%20a%20few%20articles%20and%20watched%20a%20few%20videos%20on%20adding%20attachments%20as%20well%20and%20they%20all%20have%20me%20asking%20more%20questions%20than%20answer%20being%20provided%20(what%20portion%20of%20code%20i%20actually%20need%20for%20attachments%20vs%20which%20ones%20are%20for%20the%20email)%20since%20the%20code%20for%20the%20email%20they%20use%20is%20quite%20different%20from%20mine.%26nbsp%3B%20I%20can%20only%20do%20the%20basics%20and%20learn%20by%20doing%2Fseeing.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Enot%20going%20to%20lie%20but%20the%20email%20code%20i%20used%20was%20just%20a%20copy%20and%20paste%20from%20a%20recent%20article%20with%20small%20changes.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-389203%22%20slang%3D%22en-US%22%3ERe%3A%20vba%20sending%20email%20w%2F%20attachment%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-389203%22%20slang%3D%22en-US%22%3EYou%20cannot%20add%20attachments%20by%20adding%20the%20path%20to%20the%20body%2C%20you%20need%20the%20.AddAttachment%20method%3A%20%3CBR%20%2F%3E.AddAttachment%20%22C%3A%5CUsers%5Ctabor%5CDocuments%5C%22%20%26amp%3B%20WBname%20%26amp%3B%20%22.xlsx%22%3C%2FLINGO-BODY%3E
katrina bethea
Contributor

long bit of code and im sure you all don't need all of it but its here for reference. The email portion works fine when under strBody i have text or a range with "". the problem im having is with getting it to upload a file path for an attachment. do i have to change all my code or is there just a slight typo.

 

the WBname portion of it is a public variable defined in a different module and works like it should within its own module (the following module).

 

Option Explicit
Public Sub BlkLst_Save()

Public WBname As String
WBname = "BlackList" & ActiveSheet.Name & Format(Now(), "MMM dd, yyyy")

Workbooks.Add
ActiveWorkbook.SaveAs Filename:=WBname

Workbooks("blacklist system").Activate
Range("A1:F150").Select
Selection.Copy

Workbooks(WBname).Activate
Range("A1").Select
ActiveSheet.Paste

End Sub

 

so the above works fine. Below is the email portion of this and runs into an error when trying to pull from that save path as previously stated. I have bolded and italicized the portion that errors out. (**** indicate deleted information for security)

 

 

Public Sub M_Emailer()
'sends email to Marik for blacklisted devices

Dim CDO_Mail As Object
Dim CDO_Config As Object
Dim SMTP_Config As Variant
Dim strSubject As String
Dim strFrom As String
Dim strTo As String
Dim strCc As String
Dim strBcc As String
Dim strBody As String

strSubject = "Blacklist From CDR"
strFrom = "*******"
strTo = "********"
strCc = ""
strBcc = ""
strBody = C:\Users\tabor\Documents\&WBname&.xlsx

 

Set CDO_Mail = CreateObject("CDO.Message")
On Error GoTo Error_Handling

Set CDO_Config = CreateObject("CDO.Configuration")
CDO_Config.Load -1

Set SMTP_Config = CDO_Config.Fields

With SMTP_Config
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "*******"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "*******"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Update
End With

With CDO_Mail
Set .Configuration = CDO_Config
End With

CDO_Mail.Subject = strSubject
CDO_Mail.From = strFrom
CDO_Mail.To = strTo
CDO_Mail.TextBody = strBody
CDO_Mail.CC = strCc
CDO_Mail.BCC = strBcc
CDO_Mail.Send

Error_Handling:
If Err.Description <> "" Then MsgBox Err.Description

End Sub

7 Replies
Solution
You cannot add attachments by adding the path to the body, you need the .AddAttachment method:
.AddAttachment "C:\Users\tabor\Documents\" & WBname & ".xlsx"

@Jan Karel Pieterse 

I can't seem to figure out how this one works. i tried to just copy and paste what you put with no success. Looked up quite a few articles and watched a few videos on adding attachments as well and they all have me asking more questions than answer being provided (what portion of code i actually need for attachments vs which ones are for the email) since the code for the email they use is quite different from mine.  I can only do the basics and learn by doing/seeing. 

 

not going to lie but the email code i used was just a copy and paste from a recent article with small changes. 

Perhaps you can find what you need here: http://rondebruin.nl/win/s1/cdo.htm

so heres what i have now.

 

Public Sub M_Emailer()
'creates the save file to send
Dim WBname As String
WBname = "BlackList" & ActiveSheet.Name & Format(Now(), "MMM dd, yyyy")

Workbooks.Add
ActiveWorkbook.SaveAs Filename:=WBname

Workbooks("blacklist system").Activate
Range("A1:F150").Select
Selection.Copy

Workbooks(WBname).Activate
Range("A1").Select
ActiveSheet.Paste
'sends email to Marik for blacklisted devices
Dim CDO_Mail As Object
Dim CDO_Config As Object
Dim SMTP_Config As Variant
Dim strSubject As String
Dim strFrom As String
Dim strTo As String
Dim strCc As String
Dim strBcc As String
Dim strBody As String
Dim strAtch As String

strSubject = "Blacklist From CDR"
strFrom = "email"
strTo = "email"
strCc = ""
strBcc = ""
strBody = WBname
strAtch = "C:\Users\tabor\Documents\" & WBname & ".xlsx"

Set CDO_Mail = CreateObject("CDO.Message")
On Error GoTo Error_Handling

Set CDO_Config = CreateObject("CDO.Configuration")
CDO_Config.Load -1

Set SMTP_Config = CDO_Config.Fields

With SMTP_Config
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "email"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "pass"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Update
End With

With CDO_Mail
Set .Configuration = CDO_Config
End With

CDO_Mail.Subject = strSubject
CDO_Mail.From = strFrom
CDO_Mail.To = strTo
CDO_Mail.TextBody = strBody
CDO_Mail.Attachment = strAtch
CDO_Mail.CC = strCc
CDO_Mail.BCC = strBcc
CDO_Mail.Send

Error_Handling:
If Err.Description <> "" Then MsgBox Err.Description

End Sub

 

now i get "object doesn't support this property or method" when it gets to the CDO_Mail.Attachment = strAtch line ? most of the articles im looking at utilize outlook and not CDO. The link you posted was one article i've gone over and even downloaded his modules to go through them and try to decode them but what he has written down isn't notated very well to where someone as inexperienced as i can understand whats going on. all this is way over my head and why im asking for help.

Hi,

Message object is not have a Attachment property.
there is an Attachments property, but it is read only.

 

Use the AddAttachment method when you want to attach a file.

 

https://devblogs.microsoft.com/scripting/how-can-i-attach-a-file-to-an-email-sent-using-cdo/


Regards,
kinuasa

no sure if i typed something in wrong before or what but now its working???  thx for the help guys! took out all my other code that pertained to trying and uploading an attachment and just added this one piece at the bottom:

 

CDO_Mail.Subject = strSubject
CDO_Mail.From = strFrom
CDO_Mail.To = strTo
CDO_Mail.TextBody = strBody
CDO_Mail.AddAttachment "C:\Users\tabor\Documents\" & WBname & ".xlsx"
CDO_Mail.CC = strCc
CDO_Mail.BCC = strBcc
CDO_Mail.Send

 

thought i had already tried that and it wasn't working. Not going to mess with it anymore that's for sure lol.

Excellent, thanks for letting us know.
Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
16 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
cntvertex in Discussions on
11 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies