Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 333
Default InputBox buttons

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 419
Default InputBox buttons

Karen,

If I remember correctly, you can't capture the buttons from the input box.

The input box returns a string. If you click OK, then it retruns whatever
is in the textbox. If you click Cancel, it returns an empty string ""
(...or does it return FALSE...look up input box in HELP).

Then you would test the button like this:

If NewHeader = "" then
'message to user that "Cancel" was pushed
exit sub
else
'commands to work with string entered in the input box
end if

HTH,

Conan





"Karen53" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,316
Default InputBox buttons

The constants returned by a message box are numeric values, not strings. Try
something similar to the code below to capture the click to a variable named
intOK

dim intOK as Integer

intOK = MsgBox("Yada, yada, yada...",vbQuestion+vbOkCancel,"Title Goes Here")

More code here based upon response...

Go to the VBE (Alt + F11) and in the Help Question Box type "Intrinsic
Constants" sans quotes. Then select MsgBox constants from the result list to
see a full list of message box buttons and their return values.
--
Kevin Backmann


"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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default InputBox buttons

Using vbOK, vbCancel, vbAbort etc. works for the MsgBox function. These are
enumerated (builtin) integer constants (technically type Long) recognized by
VBA. For example:
MsgBox vbOK
MsgBox vbCancel
MsgBox vbAbort
MsgBox vbRetry
MsgBox vbIgnore

InputBox returns a string containing the content of the what was typed in
the textbox or an empty string ("") if the Cancel button was clicked. Same
happens if you don't type anything and click OK, which amounts to the same
thing so this should't be a problem.

Try:
Dim NewHeader as String
NewHeader = InputBox("Specify a header name...")
If NewHeader < "" Then ActiveCell.Value = NewHeader

Greg


"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

  #5   Report Post  
Posted to microsoft.public.excel.programming
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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default InputBox buttons

hi
i think you're using it slight the wrong way.
Dim st As String
st = InputBox("enter something")
If Not st = "" Then 'user clicked cancel
'do something
else
do something else
end if
regards
FSt1

"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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default InputBox buttons

hi
try this
Dim r As String
r = InputBox("enter something")
If Not r = "" Then 'user clicked cancel
'do something
else
'do something else
end if

Regards
FSt1
"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

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default InputBox buttons

sorry for the double post. i got caught up in a email varification loop and
didn't know my first post went through. Has anyone noticed that communities
newsgroups has been acting a little weird lately?

regards
FSt1

"FSt1" wrote:

hi
try this
Dim r As String
r = InputBox("enter something")
If Not r = "" Then 'user clicked cancel
'do something
else
'do something else
end if

Regards
FSt1
"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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Option Buttons/Radio Buttons John Calder New Users to Excel 7 May 16th 08 03:51 AM
have toggle buttons but everytime print preview buttons move TinSandhu Excel Discussion (Misc queries) 1 October 11th 06 02:57 PM
Replacing macro buttons with a new set of buttons jonco Excel Programming 3 July 3rd 06 01:36 AM
buttons on InputBox jojotherider[_2_] Excel Programming 4 July 14th 05 05:07 PM
Inputbox and Application.InputBox Maria[_7_] Excel Programming 1 September 20th 04 11:36 AM


All times are GMT +1. The time now is 08:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"