Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-25-2013, 10:38 PM
aqhibjaveed aqhibjaveed is offline Email Document via Commandbutton Windows 7 32bit Email Document via Commandbutton Office 2010 32bit
Novice
Email Document via Commandbutton
 
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
  #2  
Old 03-25-2013, 11:22 PM
macropod's Avatar
macropod macropod is offline Email Document via Commandbutton Windows 7 64bit Email Document via Commandbutton Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi aqhibjaveed,

Please don't hijack old threads, especially when they're not dealing with the same issue - start a new one. I have split your post off to a new thread.

Also, when posting code, please use the code tags. They're on the 'Go Advanced' tab.

As for the code you posted, I note that you haven't defined your variables and that, you refer to the message box as 'yourMsg' but then you don't test it! Instead, you test 'response'. That's just poor coding. Had you defined either of these variables and were you requiring variable declarations via 'Option Explicit', the error would have been trapped as soon as you tried to run the code.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best office document and email search tool borabora1001 Office 0 02-21-2013 11:35 PM
Macro to send document in email AnneN Word VBA 1 02-05-2013 08:08 PM
Email Document via Commandbutton email link in document to email the document mamig Word 5 05-25-2012 10:26 AM
Adding an Email Button to a Word Document maddoktor Word 0 12-01-2011 01:32 PM
Send document as email pat-ty Word 0 09-09-2010 10:23 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:00 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft