Vba to send Email Discretely

wilster98

New Member
Joined
May 11, 2016
Messages
25
Hello VBA Gurus.
I have a form that automates portions of an AS9102 report. The report is on a secure server, but people like to save a copy to a network folder. I have to go on a search and destroy mission every so often. What I want to do is add to one of the macros when I find these bootleg copies that will discretely send an Email that a bootleg copy is being used. Can this be done so that the operator is none the wiser?

Thanks In advance, Willy
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
VBA Code:
Sub Mail_workbook_Outlook()

Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next

With OutMail
.To = "YourEmailAddressHere"
.CC = ""
.BCC = ""
.Subject = "Your Subject"
.Body = "Bootleg copy being used by " & Application.UserName
'.Display    'or you can use .Send to autosend the email without first reviewing
.Send
End With

On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing

End Sub
 
Last edited:
Upvote 0
'its worth noting that outlook's default settings will alert the user that another app is trying to send an email.
 
Upvote 0
Thank You, that is brilliant. It sends the email without alerting the user.


VBA Code:
Sub Mail_workbook_Outlook()

Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next

With OutMail
.To = "YourEmailAddressHere"
.CC = ""
.BCC = ""
.Subject = "Your Subject"
.Body = "Bootleg copy being used by " & Application.UserName
'.Display    'or you can use .Send to autosend the email without first reviewing
.Send
End With

On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing

End Sub
 
Upvote 0
What if they disable VBA code? Then that won't run.
Also, how does it distinguish where it is being run from in the code (secure server vs. network folder)?
 
Upvote 0
What if they disable VBA code? Then that won't run.
Also, how does it distinguish where it is being run from in the code (secure server vs. network folder)?

Great question. The macros are password protected, and I am one of 4 people with the password.
The macro does not distinguish where the form is stored. When I find a bootleg copy I add the code to to the form so that I know when it is opened.
The code runs when the workbook is open.
 
Upvote 0

Forum statistics

Threads
1,214,392
Messages
6,119,255
Members
448,879
Latest member
oksanana

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