Hi, I have the following piece of code, I'm cautious that when users save down a certain .pdf that they won't spell it properly for the macro to catch it. I need to add an on error .. msgbox "BS30 not found, please attach manually." and then carry on next line.
See bold line on where I need to error trap.
Thanks,
See bold line on where I need to error trap.
Thanks,
Code:
Sub EmailDocument()
Dim OApp As Object, OMail As Object, signature As String, PDFfile As String, Commercial As String, Team As String, VM As String
Dim WBA As Workbook
Dim FPath As String, PPath As String, BSR As String, BSRATP As String, PDFBS30 As String
Dim Season As Range, Yr As Range, Wk As Range, Day As Range, FName As Range, RngCopied As Range
Set OApp = CreateObject("Outlook.Application")
Set OMail = OApp.CreateItem(0)
Set WBA = ActiveWorkbook
Set Season = ActiveWorkbook.Sheets(3).Range("T12")
Set Yr = ActiveWorkbook.Sheets(3).Range("T13")
Set Wk = ActiveWorkbook.Sheets(3).Range("T14")
Set Day = ActiveWorkbook.Sheets(3).Range("T15")
Set FName = ActiveWorkbook.Sheets(3).Range("AB9")
Set RngCopied = ActiveWorkbook.Sheets(4).Range("A2:D7")
PPath = "XXXX"
BSR = PPath & Season & Yr & "\"
'BSRATP = BSR & "XXX"
FPath = BSR & "Week " & Wk & "\"
'Wrap quotes marks and connect with & if starting new line e.g "xxx@xxx.com " & "yyy@yyy.com " & "zzz@zzz.com "
'Please update add to the bottom of commercial chain if new email addresses.
Commercial = XXXX
'XXXX
VM = XXXX
'XXX team.
Team = XXXX
With OMail
.Display
End With
PDFfile = FPath & FName & ".pdf"
PDFBS30 = "XXXXX"
signature = OMail.htmlbody
With OMail
.To = Commercial & VM
.cc = Team
.Subject = FName
.attachments.Add PDFfile
[B] .attachments.Add PDFBS30[/B]
.htmlbody = "<p style='font-family;calibri;font-size:13'>" & "Please find attached." & "</p" & vbNewLine & RangetoHTML(RngCopied) & vbNewLine & signature
.Display
End With
Set OMail = Nothing
Set OApp = Nothing
End Sub