+ Reply to Thread
Results 1 to 9 of 9

How to avoid "Cancel" with Application.InputBox

  1. #1
    Forum Contributor
    Join Date
    06-27-2013
    Location
    Nebraska
    MS-Off Ver
    Office 365
    Posts
    115

    How to avoid "Cancel" with Application.InputBox

    Hello,

    I am using an Application.InputBox when the workbook is opened to prompt the user to input the their initials. These initials are used in other modules throughout the workbook. I added a While loop to keep prompting the user to enter a valid string which is working, but I still get errors if they click "Cancel" on the InputBox. Is there a way I can either keep the user from clicking "Cancel" or at least continue to prompt them to enter their initials if they do?

    Please Login or Register  to view this content.
    Thank you!

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,097

    Re: How to avoid "Cancel" with Application.InputBox

    What about
    Please Login or Register  to view this content.
    - Battle without fear gives no glory - Just try

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: How to avoid "Cancel" with Application.InputBox

    This will keep prompting unless the user enters something.
    Please Login or Register  to view this content.
    PS Wouldn't it be better to allow the user to use the Cancel button and if the do close the workbook or something?
    If posting code please use code tags, see here.

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: How to avoid "Cancel" with Application.InputBox

    I have zero sympathy for this type of user behaviour (it's deliberate naughtiness)
    - a short sharp shock is my prescription

    If the user misbehaves, code simply closes the workbook without warning
    - the user will never do it again

    Please Login or Register  to view this content.

    I would not bother with the message box....
    Does user need/want to be thanked for entering their initials?
    Does the user really want to click on a message box?
    IMHO - it is not adding a lot of value
    Last edited by kev_; 04-05-2018 at 10:36 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  5. #5
    Forum Contributor
    Join Date
    06-27-2013
    Location
    Nebraska
    MS-Off Ver
    Office 365
    Posts
    115

    Re: How to avoid "Cancel" with Application.InputBox

    PCI,

    That works for detecting "Cancel", but now I get a Type mismatch error if I select "OK" without entering a string. Before the change selecting "OK" without entering a string would prompt the user to enter a valid sting. I should mention that I have EnterInitials as Public Enterinitials As String defined in a module and not in the ThisWorkbook section.

    Thank you
    Last edited by erice; 04-05-2018 at 10:42 AM.

  6. #6
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,097

    Re: How to avoid "Cancel" with Application.InputBox

    See test file attached: There is no issue
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    06-27-2013
    Location
    Nebraska
    MS-Off Ver
    Office 365
    Posts
    115

    Re: How to avoid "Cancel" with Application.InputBox

    I was able to get that to work by putting False in quotations to make the type mismatch go away as Norie suggested. Thank you all for the replies!

  8. #8
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: How to avoid "Cancel" with Application.InputBox

    try
    Public Enterinitials As Variant
    - it needs to cope with string and boolean

  9. #9
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,097

    Re: How to avoid "Cancel" with Application.InputBox

    @kev_
    " it needs to cope with string and boolean"

    Enterinitials is already variant as there is no Dim Statement !!! No ??

    @erice
    is the file sent make the same error ??

    Thank you for details

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] UserForm with "Cancel" and "Proceed" buttons
    By kappa0815 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-06-2017, 07:31 AM
  2. [SOLVED] Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box
    By Kenny Blackwell in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 08-31-2015, 10:00 AM
  3. Replies: 2
    Last Post: 01-15-2015, 04:45 PM
  4. cancel button Application.Inputbox
    By TimlmiT in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-20-2014, 02:30 PM
  5. [SOLVED] Error when hitting cancel on Application.InputBox
    By wigtown_deano in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-05-2013, 05:26 AM
  6. [SOLVED] Application.InputBox dialog behavior with 'Nothing" input
    By rodalsa1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2013, 03:36 PM
  7. Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)" not working
    By redders in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2011, 03:52 PM

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