• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA error message in code

Jet Fusion

Member
Hi

Please can someone assist with the following code.

It works if you put in a file name but when you select cancel it gives a runtime error (see attahced and full code). I would like for if you press cancel that it gives a message dialog box with message lets say "Document not sent: whatever the text may be that can be altered.

Code:
 Sub EmailPDF()
fdir = "c:\\temp\\"
FName = InputBox("Please Enter Filename")
fPath = fdir & FName & ".pdf"
With Application
.EnableEvents = True
.ScreenUpdating = False
End With

ToAddress = ""
CCAddress = ""
CCAddress2 = ""
CCAddress3 = CCAddress & "; " & CCAddress2
MailSub = FName & " Issue Slip "

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
fPath, Quality:=xlQualityStandard, _
IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=False

Set oOutlookApp = CreateObject("Outlook.Application")


Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.To = ToAddress
.CC = CCAddress3
.Subject = MailSub


oItem.Display

oItem.Attachments.Add fPath

Set OutMail = Nothing
Set OutApp = Nothing
Set fs = CreateObject("Scripting.FileSystemObject")

fs.deletefile fPath

End With
End Sub
Thank you in advance :)
 

Attachments

Keetoowah

New Member
Hi,
just add after the line:
Code:
FName = InputBox("Please Enter Filename")
this code:
Code:
If FName = "" Then
MsgBox "Document not sent"
End If
Exit Sub
 
Top