Inputbox when cancelled

S

Sandy

I have the following

Sub NewName()
ActiveWorkbook.Unprotect

Sheets("Current Round").Unprotect Password:="*******"

Application.ScreenUpdating = False
Application.EnableEvents = False

Dim inputText As String
Dim newFileName As String

inputText = Application.InputBox("Enter name here", _
"Person's Name", , , , , 2)

*******More Code********

End Sub

What I would like is that if the inputbox cancel button is clicked then

ActiveWorkbook.Protect
Sheets("Current Round").Protect Password:="*******"

Application.ScreenUpdating = True
Application.EnableEvents = True

Exit Sub

otherwise run the ********More Code*******

How do I incorporate that into the Sub?

Thanks
Sandy
 
F

FSt1

hi
i think after the input box....
if inputtext = "" then
exit sub
end if
run more code?
or
if inputText = Application.InputBox("Enter name here", _
"Person's Name", , , , , 2) = "" then
exist sub
else
run more code?
end if
and i sure there are more "or's" but basicly if inputbox is a null string
ie canceled .... exit sub

regards
FSt1
 
S

Sandy

FSt1
Thank you.
I must admit I thought there would be some way of catching the click on the
cancel button (vbCancel) as it can on a MsgBox.
The method you describe will do the job nicely though.
Sandy
 
D

Dave Peterson

I saw this while lurking in one of the VB ng's.

The one warning was this:

While I don't like the InputBox function and would rather build my own, nicer
looking one, there is a way to tell (but it is guaranteed *not* to work in
VB.NET). It uses the
undocumented StrPtr function.

Dim strInput As String
strInput = InputBox("do something")
If Len(strInput) = 0 Then
If StrPtr(strInput) = 0 Then
MsgBox "The user clicked Cancel"
Else
MsgBox "The user clicked Enter, but typed nothing"
End If
End If
 
R

Rick Rothstein \(MVP - VB\)

I must admit I thought there would be some way of catching
the click on the cancel button (vbCancel)...

There is; use this subroutine structure as a guideline...

Sub Test()
Dim strInput As String
strInput = InputBox("Some prompt for input")
If Len(strInput) = 0 Then
If StrPtr(strInput) = 0 Then
MsgBox "User clicked Cancel Button"
Else
MsgBox "No text entry, user clicked Enter"
End If
Else
MsgBox "The user inputted this text: " & strInput
End If
' The subroutine code continues here
End Sub

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Save as troubles 3
Workbook_BeforeClose 2
Workbook_BeforeClose 3
Custom Toolbar Add-in 1
Prevent code running 3
Protection Password Prompt Problem 1
Workbook_BeforeSave 8
x=inputbox 2

Top