Results 1 to 3 of 3

Thread: Froce to save and send e-mail

  1. #1

    Froce to save and send e-mail



    Register for a FREE account, and/
    or Log in to avoid these ads!

    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.

  2. #2
    Conjurer Simi's Avatar
    Join Date
    Feb 2012
    Location
    Utah, USA
    Posts
    187
    Articles
    0
    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.

  3. #3
    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •