TkdKidSnake
Board Regular
- Joined
- Nov 27, 2012
- Messages
- 245
- Office Version
- 365
- Platform
- Windows
Hi all,
I am after some help, I use the following code to call a sheet and then produce it as a PDF, then it sets up the email ready to send - this is setup for 200 sheets and rather than make the button call up on active sheets where I have not used ' to negate the call. Is there a way of putting code in to say if sheet not found go to end sub?
The sheets all start from S1 through to S200 and rather than negate the call code I would like to include perhaps an error handler if thats the best way of doing it.
Thanks for any help you can provide.
I am after some help, I use the following code to call a sheet and then produce it as a PDF, then it sets up the email ready to send - this is setup for 200 sheets and rather than make the button call up on active sheets where I have not used ' to negate the call. Is there a way of putting code in to say if sheet not found go to end sub?
Code:
Sub ScorecardPdf001()
Application.ScreenUpdating = False
Sheets("S1").Select
'Home Location
'ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\Steve\Desktop\Supplier Scorecard\Scorecard PDFs\" & Range("AL1") & Range("AE4").Value, Quality:=xlQualityStandard, IncludeDocProperties:= _
True, IgnorePrintAreas:=False, OpenAfterPublish:=False
'Work Location
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"\\pel.com\group\Resources\Purchasing\Public\Supplier KPI\Scorecard Bedford - Red Cards - IDs - Protected Stock - OTIF\Scorecard PDFs\" _
& Range("AL1") & Range("AE4").Value, Quality:=xlQualityStandard, IncludeDocProperties:= _
True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Dim OutApp As Object
Dim OutMail As Object
Dim fname As String, sendto As String, sendcc As String, sendbcc As String, sendsubject As String, sendbody As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Check sheet names, paths, cell locations and email text below
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
fname = "\\zzz.com\group\Resources\Purchasing\Public\Supplier KPI\Scorecard Bedford - Red Cards - IDs - Protected Stock - OTIF\Scorecard PDFs\" & Range("AL1") & Range("AE4").Value
sendto = Sheets("S1").Range("AE16").Value
sendcc = Sheets("Emails").Range("C397").Value
sendbcc = Sheets("Emails").Range("C399").Value
sendsubject = Sheets("S1").Range("AE4").Value
sendbody = "<H3><B>Dear Supplier,</B></H3>" & _
"Attached is our latest Scorecard for yourselves which has now been updated to include all<br>" & _
"the relevant data transactions from the previous month.<br><br>" & _
"Please review and contact me or any member of the management team here<br>" & _
"at zzz manufacturing if you would like to discuss further.<br>" & _
"<br><br><B>Thank you for your continued support.<br></B>"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fname, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.Display
'.send
.To = sendto
.CC = sendcc
.BCC = sendbcc
.Subject = sendsubject
.HTMLBody = sendbody & "<br>" & .HTMLBody
.Attachments.Add fname & ".pdf"
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Sheets("Data Entry").Select
Application.ScreenUpdating = True
End Sub
The sheets all start from S1 through to S200 and rather than negate the call code I would like to include perhaps an error handler if thats the best way of doing it.
Thanks for any help you can provide.