View Single Post
 
Old 03-25-2013, 10:38 PM
aqhibjaveed aqhibjaveed is offline Windows 7 32bit Office 2010 32bit
Novice
 
Join Date: Mar 2013
Posts: 1
aqhibjaveed is on a distinguished road
Default Email Document via Commandbutton

Hi below is my code basically if user click the command button he will get a msg box with yes no if the response is yes i want the below code to run (Save the document and send an email) please have a look

Code:
Private Sub CommandButton1_Click()
yourMsg = MsgBox("Do you want to send the report", vbInformation + vbYesNo, "SUBMIT REPORT")
If response = vbYes Then
  ActiveDocument.Save
  Dim OutApp As Object
  Dim OutMail As Object
 
  Set OutApp = CreateObject("Outlook.Application")
  Set OutMail = OutApp.CreateItem(0)
 
  On Error Resume Next
  With OutMail
    .To = "abc@gmail.com"
    .CC = ""
    .BCC = ""
    .Subject = "Sales Report"
    .Body = "Hi All!"
    .Attachments.Add ("C:\Users\aqhibj\Desktop\Formats\Sales report__V0.2.docx")
    .Display
  End With
  On Error GoTo 0
 
  Set OutMail = Nothing
  Set OutApp = Nothing
End If
End Sub
When i run the above code i am getting msg box when i click yes its not displaying mail or saving my active document. please help

Last edited by macropod; 03-25-2013 at 11:15 PM. Reason: Added code tags & formatting
Reply With Quote