randersonTM
New Member
- Joined
- Aug 29, 2013
- Messages
- 3
Trying to valdate a couple of cells before I allow the file to be saved and sent via email.
I keep getting the error:
(References the line of code "PName = Range("A3:D3") on Debug)
Run-time error '91':
Object variable or With block variable not set
Not sure what my error is or if there's an easier way to validate the cells.
Any help is greatly appreciated.
Thanks
I keep getting the error:
(References the line of code "PName = Range("A3:D3") on Debug)
Run-time error '91':
Object variable or With block variable not set
Not sure what my error is or if there's an easier way to validate the cells.
Any help is greatly appreciated.
Thanks
Code:
Sub Email_Sheet()
Dim oApp As Object
Dim oMail As Object
Dim LWorkbook As Workbook
Dim LFileName As String
Dim PName As Range
Dim PCode As Range
Dim PLot As Range
Dim PPlan As Range
Dim PElev As Range
PName = Range("A3:D3")
PCode = Range("F3:G3")
PLot = Range("I3:J3")
PPlan = Range("L3")
PElev = Range("N3")
If ActiveSheet.PName.Value = "" Then
MsgBox "Cannot send until required cells have been completed!"
Cancel = True
ElseIf ActiveSheet.PCode.Value = "" Then
MsgBox "Cannot send until required cells have been completed!"
Cancel = True
ElseIf ActiveSheet.PLot.Value = "" Then
MsgBox "Cannot send until required cells have been completed!"
Cancel = True
ElseIf ActiveSheet.PPlan.Value = "" Then
MsgBox "Cannot send until required cells have been completed!"
Cancel = True
ElseIf ActiveSheet.PElev.Value = "" Then
MsgBox "Cannot send until required cells have been completed!"
Cancel = True
Else
LFileName = LWorkbook.Worksheets(1).Name
On Error Resume Next
Kill LFileName
On Error GoTo 0
LWorkbook.SaveAs Filename:=LFileName
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
With oMail
.To = "EMAIL"
.Subject = "Field Purchasing Error Form - Test Example"
.body = "The file is attached"
.Attachments.Add LWorkbook.FullName
.Send
End With
LWorkbook.ChangeFileAccess Mode:=xlReadOnly
Kill LWorkbook.FullName
LWorkbook.Close SaveChanges:=False
Application.ScreenUpdating = True
Set oMail = Nothing
Set oApp = Nothing
End If
End Sub
Last edited by a moderator: