+ Reply to Thread
Results 1 to 10 of 10

Send Email with MsgBox vbOk

Hybrid View

  1. #1
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Send Email with MsgBox vbOk

    Hi all,

    I have a message box with OK and Cancel. I need to have Excel send an email if the user presses ok or to not send if the user presses cancel. I have the code to send emails but I don't know how to apply it to a message box vbOk. I tried the following:
    If vbOK Then
            ActiveWorkbook.SendMail _
                Recipients:="mvasas@hydro.mb.ca", _
                Subject:="IPI Charting Tool Feedback " & Format(Date, "dd/mmm/yy")
            Else
                Exit Sub
            End If
    but this runs the sendmail no matter which button I press. Please help.

    Regards:
    Last edited by Mordred; 06-16-2011 at 05:24 PM.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  2. #2
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Send Email with MsgBox vbOk

    hi Mordred,
    I use this one, try it and see if it helps you
    If MsgBox("Do you want to send it now?", vbYesNo + vbQuestion) = vbYes Then
    
    'yr code 
    
     Else
         ' Do nothing
    End If
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  3. #3
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Send Email with MsgBox vbOk

    The purpose of this is for feedback from users throughout the corporation. Instead of the code I used in my previous post, is there a way that a New Message from Outlook can be opened with my email and subject already filled?

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Send Email with MsgBox vbOk

    Mordred,

    Here's an example for Ok/Cancel messagebox:
    Sub OkCancelExample()
        
        Dim UserInput As Integer
        UserInput = MsgBox(Title:="Input Title", _
                           Prompt:="Press OK or Cancel", _
                           Buttons:=vbOKCancel)
        If UserInput = vbOK Then
            MsgBox "Pressed OK"
        Else
            MsgBox "Pressed Cancel"
        End If
        
    End Sub


    Hope that helps,
    ~tigeravatar

    EDIT: Looks like I should refresh faster, heh

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Outlook

    Sub snb()
      If MsgBox("Do you want to send it now?", vbYesNo + vbQuestion) = vbYes Then
        with createobject("Outlook.application").createitem(0)
          .to ="mvasas@hydro.mb.ca"
          .subject = "IPI Charting Tool Feedback " & Format(Date, "dd/mmm/yy")
          .attachments.add thisworkbook.fullname
          .send
        end with
      End If
    End Sub
    Last edited by snb; 06-16-2011 at 05:08 PM.



  6. #6
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Send Email with MsgBox vbOk

    Thanks all I really appreciate this but how can the person sending this actually add to the body of the email, if they want to add a message to the email?

  7. #7
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Send Email with MsgBox vbOk

    I am going to try and incorporate the Sub from here to hopefully achieve my desired results.

  8. #8
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Send Email with MsgBox vbOk

    using snb's code add
    '
    '
    .body = ""
    '.send
    .display
    Last edited by john55; 06-16-2011 at 05:34 PM. Reason: add "display"

  9. #9
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Send Email with MsgBox vbOk

    Thanks again everyone!

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Send Email with MsgBox vbOk

    Sub snb()
      If MsgBox("Do you want to send it now?", vbYesNo + vbQuestion) = vbYes Then
        with createobject("Outlook.application").createitem(0)
          .to ="mvasas@hydro.mb.ca"
          .subject = "IPI Charting Tool Feedback " & Format(Date, "dd/mmm/yy")
          .body="This is your message"
          .attachments.add thisworkbook.fullname
          .send
        end with
      End If
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1