email via userfrom?

  • Thread starter TotallyConfused
  • Start date
T

TotallyConfused

Can someone please help revise this so that before sending email a Msgbox
will let user know it is sending email. Another msgbox to let user know when
it is done emailing. I do not want the user to have option to send. When
user clicks on Outmail (command button) it will email right away and only a
message box will let them know sending and complete. Thank you.

Private Sub OutMail_Click()
'Working in 2000-2007
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim OutApp As Object
Dim OutMail As Object

Set wb1 = ActiveWorkbook

If Val(Application.Version) >= 12 Then
If wb1.FileFormat = 51 And wb1.HasVBProject = True Then
MsgBox "There is VBA code in this xlsx file, there will be no
VBA code in the file you send." & vbNewLine & _
"Save the file first as xlsm and then try the macro
again.", vbInformation
Exit Sub
End If
End If

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'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 = "Copy of " & wb1.Name & " " & Format(Now, "dd_mmm_yy")
FileExtStr = LCase(Mid(wb1.Name, InStrRev(wb1.Name, ".")))

Set wb2 = ActiveWorkbook

wb1.SaveCopyAs TempFilePath & TempFileName & FileExtStr
Set wb2 = Workbooks.Open(TempFilePath & TempFileName & FileExtStr)

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

On Error Resume Next
With OutMail
.To = "enter email address"
.CC = "enter email address"
.BCC = ""
.Subject = "enter subject"
.Body = "Report Request attached."
.Attachments.Add wb2.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Display 'or use .Display
End With
On Error GoTo 0

wb2.Close savechanges:=False

'Delete the file
Kill TempFilePath & TempFileName & FileExtStr

Set OutMail = Nothing
Set OutApp = Nothing

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

End Sub
 
F

FSt1

hi
seems to me that if they clicked the Outlook_Click button, they would know
(or should know) that they are sending mail.
but....
at the start of the code, just after all the dims, add this

MsgBox ("You are sending an e-mail.")

they will have to click the ok button to resume code.

then at the end of the code, just before end sub, add this.

MsgBox ("e-mail sent.")

regards
FSt1
 
T

TotallyConfused

Thank you for responding. You are right. However, I do not want the email
to show. I want the code below to go straight to email and send and just
have message boxes let the user know what is happening. Right now the code
below opens Outlook and lets the user have an option of enter in the email
contents. I do not want Outlook to open just to send the email. Can you
please guide me? Thank you.
 
O

OssieMac

Replace .Display with .Send

However, the system security will popup a message warning the user that an
application is attempting to send an email and the user has to confirm. As
this is a security warning I don't think there is any way of suppressing it.

Often this security message just shows as an orange title in the Taskbar and
is not the top window so the users need to be aware of it.
 
F

FSt1

ah!
you didn't mention that in your first post. which is what confused me.
sounds like you want to use the sendmail method instead which means the code
you have posted should be deleted and not modified ie start over.
the code looks like ron de bruin code so i am re-directing to to his
sendmail method.
http://www.rondebruin.nl/mail/folder1/mail1.htm

with the send mail method, you will have to have a way to tell excel WHO you
are emailing to and WHAT your are emailing. from the code you posted, it
looks like you want to email the entire workbook but that is now a guess.
remember....computers are stupid. you have to tell them everthing.

but ron has code to email everything from a workbook to a single cell, as an
attachment or as body of email. just click on the "go back to index" link at
the top of the page.

the advice i gave about the message boxes still applies.

Regards
FSt1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top