troubleshooting Question

Attempting to Attach PDF file in Excel and Email but keep getting Error

Avatar of gdunn59
gdunn59 asked on
VBAMicrosoft ExcelMicrosoft Applications
10 Comments1 Solution454 ViewsLast Modified:
I have the following VBA Code where I'm trying to attach a PDF file via Excel and everything runs fine until it gets to the .Attachments.Add line of code.

I'm getting the following error:

   Run-time error '-2147024894 (80070002)':
   Automation error
   The system cannot find the file specified.

But if I F8 (Step) through the code, the path/filename is correct.

Any clues?????



VBA Code:
Private Sub cmdEmailReport_Click()
Dim strPrevMnth As String
Dim strCurrMnth As String
Dim strPathName As String
Dim strRptName As String
Dim strEMRecipients As String
Dim strEMCCRecipients As String
Dim strEMSubject As String
Dim strEMBody As String
Dim strEMAttach As String

'Dates for Report Name
strPrevMnth = Format(DateSerial(Year(Date), Month(Now), 0), "MMM DD, YYYY")
strCurrMnth = Format(Now() - 1, "MMM DD, YYYY")

'Email Recipients
strEMRecipients = ""
strEMCCRecipients = ""

'Email Subject
strEMSubject = "Attorney Monthly Hours Report"

'Email Body
strEMBody = "Please find attached the Attorney Monthly Hours Report as of 3/8/2016."

'Path and Report Name
'strPathName = "H:\NRTEcho\ACTIVE\gdunn59\Atty Monthly Hours Report (WIP - Automate Email)\"
strPathName = "H:\NRTEcho\ACTIVE\gdunn59\"

strRptName = "Attorney Fiscal YTD Hrs Report Through " & strPrevMnth & " as of " & strCurrMnth & " - Full" & ".pdf"
'strRptName = "Attorney Fiscal YTD Hrs Report Through " & strPrevMnth & " as of " & strCurrMnth & " - Full"

strEMAttach = strPathName & strRptName

'Send Report via Email
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(0)
With Mail_Single
 .Subject = strEMSubject
 .To = strEMRecipients
 .cc = strEMCCRecipients
 .BCC = ""
 .Body = strEMBody
 .Attachments.Add (strEMAttach)
 End With
'If Err.Description "" Then MsgBox Err.Description
End Sub
Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros