When I run the following sub, the gmail is sent without the attachment. If I set a variable for the attachment, and alter the .AddAttachment statement to .AddAttachment (FName), an attachment is sent with the email but it is empty. Please help. Here is my code:
Dim iMsg AsObjectDim iConf AsObjectDim Flds AsVariantDim Msg AsStringDim iBp As CDO.IBodyPartSet iMsg = CreateObject("CDO.Message")Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1Set Flds = iConf.FieldsWith Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _="stmpCorpServer".Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")= _
InputBox("Please enter your email address").Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")= _
InputBox("Please enter your password").UpdateEndWith'Set Variables
Msg ="Record Count - "& EmlRcrdCt & vbNewLine & _"Store Count - "& EmlStrCt & vbNewLine & _"Record Count for shelf on hand > 6*+1 shelf capacity - "& _
EmlRcrdCtShlf6 & vbNewLine & _"Record count for shelf on hand > 0 and capacity 0 - "& _
EmlRcrdCtShlf0 & vbNewLine & _"Record count for quantity of adjustment=0 and adjustment quantity>0 - "& _
EmlRcrdQty0 & vbNewLine & _"Record count for quantity of adjustment>0 and adjustment quantity=0 - "& _
EmlRcrdCtQtyGrtr0 & vbNewLine & vbNewLine & _"Attached is a spreadsheet of the 'store' counts and 'shelf on hand' counts."& _
vbNewLine & _"Please let me know if you have any questions."& vbNewLine & vbNewLine & _
EmlMisStrs & vbNewLine & _
EmlLgVar & vbNewLineWith Application.ScreenUpdating =False.EnableEvents =FalseEndWith'Set email settingsOnErrorResumeNextWith iMsgSet.Configuration = iConf.To="MyEmail".From ="""Julia"" <MyEmail>".CC ="MyEmail".BCC ="".Subject ="CAO results for week ending "& LstDayInWk.TextBody = Msg.AddAttachment "C:\CAO\SS CAO we 06072014.xlsx".SendEndWithOnErrorGoTo0'Activate Control SheetWith Application.ScreenUpdating =False.EnableEvents =FalseEndWith