Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default 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

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
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
VBA 2007 -- How can I tell if the user cancelled a Save? TomThumb Excel Programming 0 September 18th 07 01:30 PM
Hyperlink operation cancelled.... Kim Excel Discussion (Misc queries) 1 June 15th 07 03:24 PM
End Sub if InputBox cancelled (False) Francis Hookham Excel Programming 5 May 15th 07 03:39 PM
Avoid unloading of .xla addins when closing books are cancelled. Zoo Excel Programming 4 February 21st 06 03:58 PM
Email Sent or Cancelled mjamici Excel Programming 1 June 15th 05 06:46 PM


All times are GMT +1. The time now is 08:19 PM.

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"