Input Box

clares

Well-known Member
Joined
Mar 14, 2002
Messages
557
Hi All

The default setting for an inputbox seems to give a OK button and a Cancel button. Is there a way that I can just have the OK button?
I have tried putting the vbOKOnly in the syntax but it doesn't seem to take any notice!

Kindest Regards
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
clares said:
Hi All

The default setting for an inputbox seems to give a OK button and a Cancel button. Is there a way that I can just have the OK button?
I have tried putting the vbOKOnly in the syntax but it doesn't seem to take any notice!

Kindest Regards
Why do you want to clear the Cancel button...why not just check to see if the user pressed Cancel in your code...

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Test()
    <SPAN style="color:#00007F">Dim</SPAN> strInput <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    
    strInput = Application.InputBox("Test this...", "Test")
    
    <SPAN style="color:#00007F">Do</SPAN> <SPAN style="color:#00007F">While</SPAN> strInput = "False" <SPAN style="color:#007F00">'if they press cancel, it will return False</SPAN>
        MsgBox "You must provide an answer for this inputbox!", vbOKOnly + vbCritical, "Test"
        strInput = Application.InputBox("Test this...", "Test")
    <SPAN style="color:#00007F">Loop</SPAN>
    
    MsgBox strInput
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 
Upvote 0
Thanks for that.

Can I assume from your answer that I have no choice but to make my own userform?

Kindest Regards

Peter
 
Upvote 0
Hi All

Tommy Gun - your example is now working in my system - thanks for the code.

Is there a way now that I can check the contents of the inputbox on the user clicking ok, and if they don't enter a value (leaving it blank) it will loop until a value is entered.

Kindest Regards
Peter
 
Upvote 0
Just a simple addition to the code...

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Test()
    <SPAN style="color:#00007F">Dim</SPAN> strInput <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    
    strInput = Application.InputBox("Test this...", "Test")
    
    <SPAN style="color:#00007F">Do</SPAN> <SPAN style="color:#00007F">While</SPAN> ((strInput = "False") <SPAN style="color:#00007F">Or</SPAN> (strInput = vbNullString)) <SPAN style="color:#007F00">'if they press cancel, it will return False</SPAN>
        MsgBox "You must provide an answer for this inputbox!", vbOKOnly + vbCritical, "Test"
        strInput = Application.InputBox("Test this...", "Test")
    <SPAN style="color:#00007F">Loop</SPAN>
    
    MsgBox strInput
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
Hi Tommy Gun

Sorry, didn't get chance to get back to you, but thanks for that.

Kind Regards

peter
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,172
Members
448,870
Latest member
max_pedreira

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top