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 = "gdunn59@abc.com"
strEMCCRecipients = "gdunn59@abc.com"
'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"
'Report
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)
.send
End With
debugs:
'If Err.Description "" Then MsgBox Err.Description
End Sub
Option Explicit
Private Sub cmdEmailReport_Click()
Dim Mail_Object As Object
Dim Mail_Single As Object
Dim strLastDayPrevMnth As String
Dim strCurrDate 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
strLastDayPrevMnth = Format(DateSerial(Year(Date), Month(Now), 0), "MMM DD, YYYY")
strCurrDate = Format(Now() - 1, "MMM DD, YYYY")
'Email Recipients
strEMRecipients = "groper@bhfs.com"
strEMCCRecipients = "groper@bhfs.com"
'Email Subject
strEMSubject = "Attorney Monthly Hours Report"
'Email Body
strEMBody = "Please find attached the Attorney Monthly Hours Report as of 3/8/2016." & vbCrLf & vbCrLf & "Thanks," & vbCrLf & vbCrLf & "Gina Roper"
'Path and Report Name
'strPathName = "H:\NRTEcho\ACTIVE\GROPER\Atty Monthly Hours Report (WIP - Automate Email)\"
strPathName = "H:\NRTEcho\ACTIVE\GROPER\"
strRptName = "Attorney Fiscal YTD Hrs Report Through " & strLastDayPrevMnth & " as of " & strCurrDate & " - Full" & ".pdf"
'strRptName = "Attorney Fiscal YTD Hrs Report Through " & strLastDayPrevMnth & " as of " & strCurrDate & " - Full"
'Report
'strEMAttach = strPathName & strRptName
strEMAttach = "H:\NRTEcho\ACTIVE\GROPER\Attorney Fiscal YTD Hrs Report Through " & strLastDayPrevMnth & " as of " & strCurrDate & " - Full" & ".pdf"
'Send Report via Email
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
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
If fs.FileExists(strEMAttach) Then
.attachments.Add (strEMAttach)
End If
.send
End With
End Sub
Option Explicit
Sub cmdEmailReport_Click()
Dim Mail_Object As Object
Dim Mail_Single As Object
Dim strLastDayPrevMnth As String
Dim strCurrDate 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
strLastDayPrevMnth = Format(DateSerial(Year(Date), Month(Now), 0), "MMM DD, YYYY")
strCurrDate = Format(Now() - 2, "MMM DD, YYYY")
'Email Recipients
strEMRecipients = "gdunn59@bhfs.com"
strEMCCRecipients = "gdunn59@bhfs.com"
'Email Subject
strEMSubject = "Attorney Monthly Hours Report"
'Email Body
strEMBody = "Please find attached the Attorney Monthly Hours Report as of 3/8/2016." & vbCrLf & vbCrLf & "Thanks," & vbCrLf & vbCrLf & "Jane"
'Path and Report Name
'strPathName = "H:\NRTEcho\ACTIVE\gdunn59\Atty Monthly Hours Report (WIP - Automate Email)\"
strPathName = "U:\DN\Accounting\Reports\KT\Atty Monthly Hours Report\201602 Atty Hrs Report\"
'strRptName = "Attorney Fiscal YTD Hrs Report Through " & strLastDayPrevMnth & " as of " & strCurrDate & " - Full" & ".pdf"
strRptName = "Attorney Fiscal YTD Hrs Report Through " & strLastDayPrevMnth & " as of " & strCurrDate & " - Full"
'Report
strEMAttach = strPathName & strRptName
'strEMAttach = "U:\DN\Accounting\Reports\Kevin\Atty Monthly Hours Report\201602 Atty Hrs Report\Attorney Fiscal YTD Hrs Report Through " & strLastDayPrevMnth & " as of " & strCurrDate & " - Full" & ".pdf"
'Send Report via Email
Dim objOutlookAttach As Object
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
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
If fs.FileExists(strEMAttach) Then
.attachments.Add (strEMAttach)
End If
'If fs.FileExists(strPathName) Then
' Set objOutlookAttach = .attachments.Add(strEMAttach)
' End If
.send
End With
End Sub
Dim fs As Object
Set fs = CreateObject("Scripting.Fi
If fs.FileExists(strEMAttach)
.Attachments.Add (strEMAttach)
End if
That looks after the error.
Then, if you don't get an attachment, you'll need to explore why the attachment file is not found to exist -- timing, still locked, exclusive access etc.