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
 

Some videos you may like

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

TommyGun

MrExcel MVP
Joined
Dec 9, 2002
Messages
4,202
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>
 

clares

Well-known Member
Joined
Mar 14, 2002
Messages
557
Thanks for that.

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

Kindest Regards

Peter
 

clares

Well-known Member
Joined
Mar 14, 2002
Messages
557

ADVERTISEMENT

Thanks for that TommyGun. Great.

Kindest Regards

Peter
 

clares

Well-known Member
Joined
Mar 14, 2002
Messages
557
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
 

TommyGun

MrExcel MVP
Joined
Dec 9, 2002
Messages
4,202
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>
 

clares

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

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

Kind Regards

peter
 

Watch MrExcel Video

Forum statistics

Threads
1,126,956
Messages
5,621,809
Members
415,857
Latest member
braunReivn

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
Top