+ Reply to Thread
Results 1 to 4 of 4

VBA code for InputBox vbCancel to run the routine

Hybrid View

  1. #1
    Registered User
    Join Date
    05-20-2005
    Location
    North Texas
    MS-Off Ver
    2007
    Posts
    9

    VBA code for InputBox vbCancel to run the routine

    I would like to know how to code for vbCancel in an InputBox. I have tried If..Then's but keep getting bugged out of the routine. Any help would be appreciated. Thanks.

    Glenn

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good morning Glenn

    You don't actually need vbCancel, but if the cancel button is clicked the value of the input box is returned to VBA as false. Yes, I know it departs from the usual rules, but that's VBA for you - and I don't think it's actually documented in the help files. Try this code;

    Sub Example()
    YourName = Application.InputBox("Please enter your name", _
    "Enter Your Name", "Name", 100, 100, , , 2)
    If YourName = False Then Exit Sub
    MsgBox "Your name is " & YourName
    End Sub

    HTH

    DominicB

  3. #3
    Registered User
    Join Date
    05-20-2005
    Location
    North Texas
    MS-Off Ver
    2007
    Posts
    9

    Thumbs up vbCancel

    Hello Dominic

    Youdaman! This has been driving me crazy because I knew VBA was absolutely perfect and I was the idiot. I'm still an idiot but a little less thanks to you.

    Thanks very much.

    Glenn

  4. #4
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hi Glenn

    You're welcome. And thank you for the feedback.

    DominicB

+ 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