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

I have the following inputbox and need to trap erros

Set Rng= Application.InputBox(Msg1, Title1, Type:=8) where Rng is dimmed as
an object

1) how do I trap the user response if they click cancel
2) how do i tarp the user response if the click Enter without selecting a
range





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Application.InputBox error trapping

Does this help?

Sub TestIt()
Dim Rng As Object
'
On Error GoTo Bad_Rng
Set Rng = Application.InputBox(Msg1, Title1, Type:=8)
On Error GoTo 0
'
MsgBox "Got to here"
Exit Sub
'
Bad_Rng:
MsgBox "Cancel button was pressed"
End Sub

If the user clicks enter and the box is blank, or has a badly formed range
in it, then the InputBox Method itself displays a warning message and doesn't
let the user get away with it. The only two ways for the user to get out are
to enter a valid range, or to press Cancel. You can trap Cancel by doing
what I did above.

Eric
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Application.InputBox error trapping

I'd probably do it this way

Sub TestIt()
Dim Rng As Object
'
Set Rng = Nothing

On Error Resume Next
Set Rng = Application.InputBox(Msg1, Title1, Type:=8)
On Error GoTo 0
'
If Rng Is Nothing Then
MsgBox ("No range was selected.")
End If
End Sub


--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"egun" wrote:

Does this help?

Sub TestIt()
Dim Rng As Object
'
On Error GoTo Bad_Rng
Set Rng = Application.InputBox(Msg1, Title1, Type:=8)
On Error GoTo 0
'
MsgBox "Got to here"
Exit Sub
'
Bad_Rng:
MsgBox "Cancel button was pressed"
End Sub

If the user clicks enter and the box is blank, or has a badly formed range
in it, then the InputBox Method itself displays a warning message and doesn't
let the user get away with it. The only two ways for the user to get out are
to enter a valid range, or to press Cancel. You can trap Cancel by doing
what I did above.

Eric

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
Application InputBox Type 8 Error Neal Zimm Excel Programming 4 January 15th 09 09:38 AM
Application.InputBox Steven Excel Programming 2 December 23rd 06 11:56 PM
application.inputbox Christmas May[_2_] Excel Programming 5 November 22nd 06 04:11 PM
Inputbox and Application.InputBox Maria[_7_] Excel Programming 1 September 20th 04 11:36 AM
application.inputbox Murat Excel Programming 4 February 24th 04 11:38 AM


All times are GMT +1. The time now is 12:05 PM.

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

About Us

"It's about Microsoft Excel"