Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
VBA 2007 -- How can I tell if the user cancelled a Save? | Excel Programming | |||
Hyperlink operation cancelled.... | Excel Discussion (Misc queries) | |||
End Sub if InputBox cancelled (False) | Excel Programming | |||
Avoid unloading of .xla addins when closing books are cancelled. | Excel Programming | |||
Email Sent or Cancelled | Excel Programming |