I want to ask user to save file after it's sent as attachment in email! (1 Viewer)

Abouya

Registered User.
Local time
Today, 07:35
Joined
Oct 11, 2016
Messages
88
I would love to prompt users " do you want to save(or not to) the file I'm sending on the attachment after they get the message: "MsgBox "Your File was successfully sent to" & " " & Range("B28") & " " & "and" & " " & Range("B29")". is there a way to do this?

Here is the code i'm using:


Code:
Sub Mail_Click()
 
 
 Dim Msg As String, Ans As Variant
 Dim wb1 As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim FileExtStr As String
    Dim OutApp As Object
    Dim OutMail As Object
    EmailTo = Cells(29, 2)
    ccto = Cells(28, 2)
    
Msg = "Clicking 'Yes' will Directly email Your PO Requisition!"
     
        Ans = MsgBox(Msg, vbYesNo)
    Select Case Ans
Case vbYes
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    Set wb1 = ActiveWorkbook

    'Make a copy of the file/Open it/Mail it/Delete it
    'If you want to change the file name then change only TempFileName
    TempFilePath = Environ$("temp") & "\"
    TempFileName = Replace(wb1.Name, ".xlsm", "") & " #" & Range("H5") & " " & Format(Now, "dd-mmm-yy")
    FileExtStr = "." & LCase(Right(wb1.Name, Len(wb1.Name) - InStrRev(wb1.Name, ".", , 1)))

    wb1.SaveCopyAs TempFilePath & TempFileName & FileExtStr

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

    On Error Resume Next
    With OutMail
        .To = EmailTo
        .CC = ccto
        .BCC = ""
        .Subject = "PO Requisition #" & " " & Range("H5")
        .Body = "Please Find the file attached."
        .Attachments.Add TempFilePath & TempFileName & FileExtStr
        'You can add other files also like this
        '.Attachments.Add ("C:\test.txt")
        .Send   'or use .Display
    End With
    On Error GoTo 0
    
    

    
    'Delete the file
    Kill TempFilePath & TempFileName & FileExtStr

    Set OutMail = Nothing
    Set OutApp = Nothing

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With

MsgBox "Your File was successfully sent to" & " " & Range("B28") & " " & "and" & " " & Range("B29")

 Case vbNo
GoTo Quit:
    End Select
Quit:

End Sub

any help is appreciated.
 

smiler44

Registered User.
Local time
Today, 15:35
Joined
Jul 15, 2008
Messages
641
why prompt them, why not just add code to save the file?

x = MsgBox(" do you want to save file", 36, "confirm")


If x = 6 Then ' yes
' not sure is this code is right
dim oSavePath As String
path of where you want to save the file
ActiveWorkbook.SaveAs oSavePath


End If
 

Users who are viewing this thread

Top Bottom