Froce to save and send e-mail

Riaz3001

New member
Joined
Mar 19, 2014
Messages
4
Reaction score
0
Points
0
Hello,

Is there a way in a VBA code, to force the user to save a VB Form and to force it to send it as an e-mail in outlook, with all the data within the form included?

save and send.

Thanks in advance.
 

Simi

New member
Joined
Feb 10, 2012
Messages
190
Reaction score
0
Points
0
Location
Utah, USA
Excel Version(s)
Version 2002 Build 12527.20194
I know there are ways to auto send emails, I have not ever used them. You may want to try using the search feature for this forum with that question.

The save function however is something I use, I actually put this in a shared workbook I have because I had 1 particular employee that would leave the shared workbook open for hours on end, and this seemed to create problems for me. So now this code will force them to save and close the workbook after being open for 10 mins.

This code I put in a new module

Code:
Option Explicit
Public dTime As Date


Public Sub time_to_close()


dTime = Now + TimeValue("00:10:00")


'MsgBox ("It has been 15 minutes since you opened the WIP, Time to save and close it!")
    If UCase(Application.UserName) = "ME" Or UCase(Application.UserName) = "MYCOWORKER" Then
        'do nothing
    Else
        Workbooks("FILENAME.XLSM").Close SaveChanges:=True
        Application.OnTime dTime, "time_to_close"
    End If
End Sub

This code needs to be added on the thisworkbook code.

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Turn off onTime calls
    If UCase(Application.UserName) = "ME" Or UCase(Application.UserName) = "MYCOWORKER" Then
        'do nothing
    Else
     Application.OnTime dTime, "time_to_close", , False
    End If


End Sub


Private Sub Workbook_Open()
    If UCase(Application.UserName) = "ME" Or UCase(Application.UserName) = "MYCOWORKER" Then
        'do nothing
    Else
        dTime = Now + TimeValue("00:10:00")
        Application.OnTime dTime, "time_to_close"
    End If
End Sub

I added the check for user name, so 1 of my coworkers and I don't get the forced save and close.
I hope this can be helpful for you.
 

Riaz3001

New member
Joined
Mar 19, 2014
Messages
4
Reaction score
0
Points
0
Hello,

Thank you very much for your response and thanks for the code it is very interesting and may come in useful in my code, I shall be using it.

How ever my question was to to force the user to save the document and then to write a vb code to find the saved file the user saved and to send it as an e-mail to myself the admin. Any ideas?

Thanks
 
Top