View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
SeanC UK[_2_] SeanC UK[_2_] is offline
external usenet poster
 
Posts: 63
Default InputBox buttons

Hi Karen,

I am not sure if you can do this with the standard InputBox. You can test
the return value, but not which button is pressed, as far as I can see.

if you use Application.Inputbox, which is slightly different, then you can
try something like:

If Application.InputBox("Blah blah") = False Then

However, if you are asking for text to be returned and the user inputs
"False" then your code will act in the same way as when you are trying to
capture the Cancel button.

The Application.InputBox does allow you to specify the type of data being
returned, and, therefore, if it is not text that you want to be returned (say
you specify that it must be a Range or a number that is to be returned) then
you can be sure that the only time False will come back is if Cancel is
pressed. If you do specify something other than text and wish to use this
method then you will find that an error occurs when cancel is pressed (as
False is not a number or Range etc) so you will have to use On Error Resume
Next before the Inputbox line.

This is all I can suggest of the top of my head, without you having to
design your own form to do this.

Hope this is of some help,

Sean.
--
(please remember to click yes if replies you receive are helpful to you)


"Karen53" wrote:

Hi,

How do I capture the OK or Cancel button on an input box?

I've tried this but I get a type mismatch error...

Dim NewHeader as String

If NewHeader = vbOK Then 'if input box was not cancelled

--
Thanks for your help.
Karen53