Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

excel to mail

  Asked By: Burak    Date: Jun 17    Category: MS Office    Views: 1019
  

Dear members of Daily Free Code,

This is my first post on this forum/website and thus please excuse any uncommon behaviour of mine. I have some programming experience but that is in C only.

I am new to VBA.

I was looking for a VBA code that would send a mail when I saved the excel file that is being worked on. I would also have liked being able to log the change into the mail but I have no clue on where to start for that last bit. :P

Could anyone please point out my error? Or rewrite the parts that have errors and point it out for me?

I have found the following and made some adjustments:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)

Dim Answer As String
Dim Mail As String

Answer = MsgBox("Would you like to save?", vbYesNo, "Save Prompt?")

If Answer = vbNo Then ActiveWorkbook.Close SaveChanges:=False


If Answer = vbYes Then


Mail = MsgBox("Would you like to mail?", vbYesNo, "Mail?")

If Mail = vbNo Then ActiveWorkbook.Close SaveChanges:=True 'hayir mail atmak istemiyorum, ama save et.
End If

If Mail = vbYes Then

'open outlook type stuff
Set OutlookApp = CreateObject("Outlook.Application")
Set OlObjects = OutlookApp.GetNamespace("MAPI")
Set newmsg = OutlookApp.CreateItem(olMailItem)
'add recipients
'newmsg.Recipients.Add ("Name Here")
newmsg.Recipients.Add ("mail@mail.com")
'add subject
newmsg.Subject = "Trial"
'add body
newmsg.Body = "BlaBlaBla"
newmsg.Display 'display
newmsg.Send 'send message
'give conformation of sent message
MsgBox "Mail Send!", , "Mail Send!"


End If

'save the document
'Me.Worksheets.Save

End Sub

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on excel to mail Or get search suggestion and latest updates.




Tagged: