+ Reply to Thread
Results 1 to 13 of 13

Getting yes & no buttons to work in MsgBox

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Getting yes & no buttons to work in MsgBox

    I think im missing an "IF" or "=" but spent hours now trying to figure this out but cant




    Private Sub email_Click()
    
    Dim resp
    
    resp = MsgBox(vbTab & "Click YES if you would you like to view common issues?" & vbCrLf & vbTab & "Or" & vbCrLf & vbTab & "click NO to email the cost model along with an issue/query?" & vbCrLf & vbTab & "Or" & vbCrLf & vbTab & "click CANCEL to return", vbYesNoCancel + vbQuestion, "User input part help?")
    
    If resp = vbNo Then
     '
     ' email Macro
     '
     '
     '
     ActiveWorkbook.Save
     'Optional parameters for xlDialogSendMail are: Recipients, Subject,
     Application.Dialogs(xlDialogSendMail).Show "name@company.co.uk", "Cost Model Query"
    End If
     
    If resp = vbYes Then
    Yes = MsgBox(vbCrLf & vbTab & "Please make sure you have done the following:" & vbCrLf & vbTab & "" & vbCrLf & vbTab & "1. Enter Category & Customer in cells C1 & C2?" & vbCrLf & vbTab & "2. Enter all information required in the part input box?" & vbCrLf & vbTab & "3. Filled all required entries in blue cells & packhouse info section?" & vbCrLf & vbTab & "4. Calculated labour hours per case in calculator tab?" & vbCrLf & vbTab & "" & vbCrLf & vbTab & "If you still require further help please email.contact name" & vbCrLf & vbTab & "" & vbCrLf & vbTab & "Email. name@Company.co.uk" & vbCrLf & vbTab & "Tel. ", vbOK)
    End If
    
    If MsgBox = vbYes Then
    'email Macro
    ActiveWorkbook.Save
    'Optional parameters for xLDialogSendMail are: Recipients, Subject,
    Application.Dialogs(xlDialogSendMail).Show "name@company.co.uk", "Cost Model Help"
    End If
    
    End Sub
    Basically i want to display the box "help? continue to common issues, email to email, cancel to return

    If they then go common issues and decide to email i want the user to email, if they think "yes the common issues help i want to go back to the sheet, then go back to the sheet?????
    Last edited by shiftyspina; 05-02-2013 at 11:57 AM. Reason: confidentiality

  2. #2
    Forum Contributor ragavan.sridar1's Avatar
    Join Date
    11-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010, Excel 2003
    Posts
    208

    Re: Getting yes & no buttons to work in MsgBox

    are you getting an error in this line?

    If MsgBox = vbYes Then???
    Thanks!
    Raga.

    Please,mark your thread [SOLVED] if you received your answer.

    Click the little star * below, to give some Rep if you think an answer deserves it.

    I learnt so many things from these links.

  3. #3
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Getting yes & no buttons to work in MsgBox

    Yes, but it is not higlighting that part, it is highlighting the Private Sub line, although before i put in the If MsgBox line it worked fine.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Getting yes & no buttons to work in MsgBox

    Hi, shiftyspina,

    maybe like this:
    Private Sub email_Click()
    
    Dim resp
    
    resp = MsgBox(vbTab & "Click YES if you would you like to view common issues?" & vbCrLf & vbTab & _
        "Or" & vbCrLf & vbTab & "click NO to email the cost model along with an issue/query?" & _
        vbCrLf & vbTab & "Or" & vbCrLf & vbTab & "click CANCEL to return", _
        vbYesNoCancel + vbQuestion, "User input part help?")
    
    Select Case resp
      Case vbNo
      '
      ' email Macro
      '
      '
      '
      ActiveWorkbook.Save
      'Optional parameters for xlDialogSendMail are: Recipients, Subject,
      Application.Dialogs(xlDialogSendMail).Show "Email", "Cost Model Query"
     
      Case vbYes
        MsgBox vbCrLf & vbTab & "Please make sure you have done the following:" & vbCrLf & vbTab & "" & _
            vbCrLf & vbTab & "1. Enter Category & Customer in cells C1 & C2?" & vbCrLf & vbTab & _
            "2. Enter all information required in the part input box?" & vbCrLf & vbTab & _
            "3. Filled all required entries in blue cells & packhouse info section?" & vbCrLf & vbTab & _
            "4. Calculated labour hours per case in calculator tab?" & vbCrLf & vbTab & "" & vbCrLf & _
            vbTab & "If you still require further help please email or contact somebody" & _
            vbCrLf & vbTab & "" & vbCrLf & vbTab & "Email. " & _
            vbCrLf & vbTab & "Tel. ", vbOK
        'email Macro
        ActiveWorkbook.Save
        'Optional parameters for xLDialogSendMail are: Recipients, Subject,
        Application.Dialogs(xlDialogSendMail).Show "Email", "Cost Model Help"
      Case vbCancel
        'whatever return means
    End Select
    
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Getting yes & no buttons to work in MsgBox

    You have provided an email id and contact no in the code in post 1. Is that real and supposed to be confidential info? If yes, please edit the code and put dummy info in.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  6. #6
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Getting yes & no buttons to work in MsgBox

    Ooops sorry, i have ammended the code now

  7. #7
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Getting yes & no buttons to work in MsgBox

    Holger that is fantastic except, cancel means basically return to spreadsheet, i added in userform.show to get it to do something, but when clicking cancel or close it still wants to send an email? i really just want it to return to the worksheet, yet whatever i put in it wants to send an email?

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Getting yes & no buttons to work in MsgBox

    Hi, shiftyspina,

    you could use either Exit Sub as command (leaving the sub just running) or End (which would stop all macros even those which called this one).

    And with the code published if you choose yes and press Ok the mail will be sent (thatīs how I understood the code you supplied). If thatīs where you have the problem please comment the lines for email macro out.

    Ciao,
    Holger
    Last edited by HaHoBe; 05-02-2013 at 12:13 PM. Reason: further explanation (italic)

  9. #9
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Getting yes & no buttons to work in MsgBox

    Hi

    What i need is if you click no in the first msgbox it sends an email, then if you click yes it shows some common issues, from that common issue msgbox it will say ok or cancel if you click ok it will send an email if you click cancel it will return to the spread sheet

    At the moment if i click cancel or close it still wants to send the email

    Private Sub email_Click()
    
    Dim resp
    
    resp = MsgBox(vbTab & "Click YES if you would you like to view common issues?" & vbCrLf & vbTab & "" & vbCrLf & vbTab & _
        "Or" & vbCrLf & vbTab & "" & vbCrLf & vbTab & "click NO to email the cost model along with an issue/query?" & vbCrLf & vbTab & "" & _
        vbCrLf & vbTab & "Or" & vbCrLf & vbTab & "" & vbCrLf & vbTab & "click CANCEL to return", _
        vbYesNoCancel + vbQuestion, "User input part help?")
    
    Select Case resp
      Case vbNo
      '
      ' email Macro
      '
      '
      '
      ActiveWorkbook.Save
      'Optional parameters for xlDialogSendMail are: Recipients, Subject,
      Application.Dialogs(xlDialogSendMail).Show "Name@Company.co.uk", "Cost Model Query"
     
      Case vbYes
        MsgBox vbCrLf & vbTab & "Please make sure you have done the following:" & vbCrLf & vbTab & "" & _
            vbCrLf & vbTab & "1. Enter Category & Customer in cells C1 & C2?" & vbCrLf & vbTab & _
            "2. Enter all information required in the part input box?" & vbCrLf & vbTab & _
            "3. Filled all required entries in blue cells & packhouse info" & vbCrLf & vbTab & "section?" & vbCrLf & vbTab & _
            "4. Calculated labour hours per case in calculator tab?" & vbCrLf & vbTab & "" & vbCrLf & _
            vbTab & "If you still require further help email or contact Name" & vbCrLf & vbTab & "Name" & _
            vbCrLf & vbTab & "" & vbCrLf & vbTab & "Email. Name@Company.co.uk " & _
            vbCrLf & vbTab & "Tel. 00000 000 000" & vbCrLf & vbTab & "" & vbCrLf & vbTab & "Click OK to send email", vbOK + vbInformation
        'email Macro
        ActiveWorkbook.Save
        'Optional parameters for xLDialogSendMail are: Recipients, Subject,
        Application.Dialogs(xlDialogSendMail).Show "Name@Company.co.uk", "Cost Model Help"
      Case vbCancel
       Exit Sub
    
    End Select

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Getting yes & no buttons to work in MsgBox

    Hi, shiftyspina,

    sorry, donīt really understand what you are after, maybe like this:
    Private Sub email_Click()
    
    Dim resp As Long
    Dim blnCancel As Boolean
    
    Do
      blnCancel = False
      resp = MsgBox(vbTab & "Click YES if you would you like to view common issues?" & vbCrLf & vbTab & "" & vbCrLf & vbTab & _
          "Or" & vbCrLf & vbTab & "" & vbCrLf & vbTab & "click NO to email the cost model along with an issue/query?" & vbCrLf & vbTab & "" & _
          vbCrLf & vbTab & "Or" & vbCrLf & vbTab & "" & vbCrLf & vbTab & "click CANCEL to return", _
          vbYesNoCancel + vbQuestion, "User input part help?")
      
      Select Case resp
        Case vbNo
        '
        ' email Macro
        '
        '
        '
        ActiveWorkbook.Save
        'Optional parameters for xlDialogSendMail are: Recipients, Subject,
        Application.Dialogs(xlDialogSendMail).Show "Name@Company.co.uk", "Cost Model Query"
        blnCancel = False
        Case vbYes
          resp = MsgBox(vbCrLf & vbTab & "Please make sure you have done the following:" & vbCrLf & vbTab & "" & _
              vbCrLf & vbTab & "1. Enter Category & Customer in cells C1 & C2?" & vbCrLf & vbTab & _
              "2. Enter all information required in the part input box?" & vbCrLf & vbTab & _
              "3. Filled all required entries in blue cells & packhouse info" & vbCrLf & vbTab & "section?" & vbCrLf & vbTab & _
              "4. Calculated labour hours per case in calculator tab?" & vbCrLf & vbTab & "" & vbCrLf & _
              vbTab & "If you still require further help email or contact Name" & vbCrLf & vbTab & "Name" & _
              vbCrLf & vbTab & "" & vbCrLf & vbTab & "Email. Name@Company.co.uk " & _
              vbCrLf & vbTab & "Tel. 00000 000 000" & vbCrLf & vbTab & "" & vbCrLf & vbTab & "Click OK to send email", vbOKCancel + vbInformation)
          Select Case resp
            Case vbOK
              'email Macro
              ActiveWorkbook.Save
              'Optional parameters for xLDialogSendMail are: Recipients, Subject,
              Application.Dialogs(xlDialogSendMail).Show "Name@Company.co.uk", "Cost Model Help"
              blnCancel = False
            Case vbCancel
              blnCancel = True
          End Select
        Case vbCancel
         blnCancel = True
      End Select
    Loop While blnCancel = True
    End Sub
    Ciao,
    Holger

  11. #11
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Getting yes & no buttons to work in MsgBox

    Hi Holger

    Thank you, i do appreciate your help but now with the loop on it just keeps restarting the first msgbox which the vbyesnocancel. When any cancel or closed is pushed i need it to completely exit the msgboxs and return to the excel sheet?

    I only want an email sent if "NO" is pushed in the first msgbox, and "OK" is pushed in the seconf msgbox
    Im sorry if im not explaining very well, and the fact i cant do it

  12. #12
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Getting yes & no buttons to work in MsgBox

    Hi, shiftyspina,

    it takes at least two persons to not understand a problem.

    Private Sub email_Click()
    
      Dim resp As Long
      
      resp = MsgBox(vbTab & "Click YES if you would you like to view common issues?" & vbCrLf & vbTab & "" & vbCrLf & vbTab & _
          "Or" & vbCrLf & vbTab & "" & vbCrLf & vbTab & "click NO to email the cost model along with an issue/query?" & vbCrLf & vbTab & "" & _
          vbCrLf & vbTab & "Or" & vbCrLf & vbTab & "" & vbCrLf & vbTab & "click CANCEL to return", _
          vbYesNoCancel + vbQuestion, "User input part help?")
      
      Select Case resp
        Case vbNo
        '
        ' email Macro
        '
        '
        '
        ActiveWorkbook.Save
        'Optional parameters for xlDialogSendMail are: Recipients, Subject,
        Application.Dialogs(xlDialogSendMail).Show "Name@Company.co.uk", "Cost Model Query"
        
        Case vbYes
          resp = MsgBox(vbCrLf & vbTab & "Please make sure you have done the following:" & vbCrLf & vbTab & "" & _
              vbCrLf & vbTab & "1. Enter Category & Customer in cells C1 & C2?" & vbCrLf & vbTab & _
              "2. Enter all information required in the part input box?" & vbCrLf & vbTab & _
              "3. Filled all required entries in blue cells & packhouse info" & vbCrLf & vbTab & "section?" & vbCrLf & vbTab & _
              "4. Calculated labour hours per case in calculator tab?" & vbCrLf & vbTab & "" & vbCrLf & _
              vbTab & "If you still require further help email or contact Name" & vbCrLf & vbTab & "Name" & _
              vbCrLf & vbTab & "" & vbCrLf & vbTab & "Email. Name@Company.co.uk " & _
              vbCrLf & vbTab & "Tel. 00000 000 000" & vbCrLf & vbTab & "" & vbCrLf & vbTab & "Click OK to send email", vbOKCancel + vbInformation)
          
          Select Case resp
            
            Case vbOK
              'email Macro
              ActiveWorkbook.Save
              'Optional parameters for xLDialogSendMail are: Recipients, Subject,
              Application.Dialogs(xlDialogSendMail).Show "Name@Company.co.uk", "Cost Model Help"
            
            Case vbCancel
              Exit Sub
          End Select
        
        Case vbCancel
          Exit Sub
      End Select
    End Sub
    Ciao,
    Holger

  13. #13
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Getting yes & no buttons to work in MsgBox

    WooHoo!!! thanks Holger works like a dream now thank you very very much

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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