ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Inputbox when cancelled (https://www.excelbanter.com/excel-programming/414667-inputbox-when-cancelled.html)

Sandy

Inputbox when cancelled
 
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

FSt1

Inputbox when cancelled
 
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




"Sandy" wrote:

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


Sandy

Inputbox when cancelled
 
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

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




"Sandy" wrote:

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



Dave Peterson

Inputbox when cancelled
 
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

Sandy wrote:

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

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




"Sandy" wrote:

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


--

Dave Peterson

Rick Rothstein \(MVP - VB\)[_2404_]

Inputbox when cancelled
 
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


All times are GMT +1. The time now is 07:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com