Like BeforePrint, but for Emailing?

JustCallMeNelson

Board Regular
Joined
Jan 20, 2006
Messages
67
Hi everyone,

I have an excel order from for customers that has a BeforePrint that works well and I am happy with:

Private Sub Workbook_BeforePrint(cancel As Boolean)
If Range("D9").Value = "" Or Range("G9").Value = "" Then
MsgBox ("Please enter your Account Name and Account Number")
cancel = True
Exit Sub
End If

If Range("G10") = "" Then
MsgBox ("Please enter an Order Reference")
cancel = True
Exit Sub
End If

If Range("G11") = "" Then
whatduedate = MsgBox("You have not stated when you need these goods (Due Date). Would you like them ASAP?", vbYesNo, "Due Date?")

End If

If whatduedate = vbYes Then
Range("G11").Value = "ASAP"
End If
If whatduedate = vbNo Then
MsgBox ("Please enter the date you would like this order delivered:")
cancel = True
Exit Sub
End If

End Sub

As I said I'm really happy with this and all I need to do is duplicate what it does, but for emails.

Can anyone help?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
What exactly do you mean by "but for emails"?
 
Upvote 0
Sorry, was that a bit unclear?

I'd like exactly the same code to run when somebody tries to email the workbook. People will either be printing this order form off and faxing it in, or completing it and then emailing it in.

I'd like the same checks to run when they try to email it via the 'File' - 'Send To' menu as when they try to print it.

Thanks!!
 
Upvote 0
There are no events related to sending, unfortunately. You could try and hook into the File-SendTo menu as long as you reset it before closing or deactivating the workbook, but you would still have the issue that they could attach it to an email outside of Excel. Is it an option to just use the BeforeSave event?
 
Upvote 0
Assuming you are interested in the Send as attachment button, you would need a class module containing code like this:
Code:
Public WithEvents btn As CommandBarButton
Private Sub btn_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
   Dim blnStop as boolean
   blnStop = ValidateData()
   if blnStop then
      msgbox "Data is invalid and must be corrected"
   CancelDefault = True
   end if
End Sub

then you need some code to hook this up - for example (assuming your class is called Class1) in a normal module you would have:
Code:
 Dim objHook As Class1
Sub hookit()
   Dim ctl As CommandBarControl
   Set objHook = New Class1
   Set ctl = Application.CommandBars.FindControl(ID:=2188)
   Set objHook.btn = ctl
End Sub
Sub unhookit()
   Set objHook = Nothing
End Sub

You would need to call the hookit procedure from the workbook open event. You would also need to change your existing code so that it is a function that returns True if the data is valid, and False otherwise.

HTH.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,272
Members
449,075
Latest member
staticfluids

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
Back
Top