VBA - tough one

David123456

New Member
Joined
Jul 16, 2014
Messages
48
Hi,

Please see VBA Code below I am struggling with code to end sub if a criteria is not met.

The line I am concerned with is

If Len(Range("d65")) = "Use Dropdown" Then Exit Sub

I want to be able to freeze screen if cell "d65" in each any sheet has the text use dropdown.


This is what I currently have this process E Mails an active sheet to a selected address - then freezes the sheet


Sub EmailWithOutlook()
Dim oApp As Object
Dim oMail As Object
Dim FilePath As String
Dim FileName As String

Application.ScreenUpdating = False

' create file name and path
FilePath = "Y:\" 'change the path as desired
FileName = FilePath & ActiveSheet.Name & ".pdf"


If ActiveSheet.Cells(65, "d").Value = "Use Dropdown" Then

MsgBox ("Please Complete!")

End If
If Len(Range("d65")) = "Use Dropdown" Then Exit Sub
'Now Export the Activesheet as PDF with the given File Name and path
Sheets(ActiveSheet.Name).ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
FileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False



'Create and show the Outlook mail item
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
With oMail
'Uncomment the line below to hard code a recipient
.To = ActiveSheet.Cells(24, "D").Text
'Uncomment the line below to hard code a subject
.Subject = ActiveSheet.Cells(12, "H").Text
'Uncomment the lines below to hard code a body
.body = ActiveSheet.Cells(21, "D").Text
'Uncomment the lines below to hard code a body
.body = ActiveSheet.Cells(23, "D").Text
.Attachments.Add FileName
.Display
End With

'Delete the temporary file


'Restore screen updating and release Outlook
Application.ScreenUpdating = True
Set oMail = Nothing
Set oApp = Nothing
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Watch MrExcel Video

Forum statistics

Threads
1,130,112
Messages
5,640,165
Members
417,128
Latest member
Xianter

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top