Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello all,
How I can I detect the response to an inputbox prompt in a macro? Neither of the inputbox methods below seem to work:
oldtext = ActiveDocument.Evaluate("vBookmarkID")
' t = ActiveDocument.GetApplication.InputBox("Enter Quote ID:",oldtext)
t = InputBox("Enter Quote ID:", "Create Quote Bookmark")
if t = vbCancel then
msgbox("Cancelled")
end if
Thanks!
Gordon
With the VB InputBox (the second one), you can determine if the user clicks Cancel or clicks Ok with a blank input. Use:
Sub Responser
t = inputbox("What is your answer")
if t = False Then
msgbox("Cancel")
ElseIf t = "" Then
msgbox("Blank Response")
Else
msgbox(t)
End If
End Sub
If you don't need an input and you just want the user to click Ok or Cancel, you should use MsgBox instead as that will return a value based on which button was clicked.
Thanks for the reply.
I had just sorted it out with a 'len' test eg
if len(t) = 0 then
msgbox("Cancelled")
else
msgbox("OKed")
end if
Interestingly, using the 'ActiveDocument.GetApplication.InputBox' method, the OK button is not available unless something is entered. This is much better than the native VBS inputbox where 'cancel ' returns a 0 length but so does nothing entered and an 'ok'
Regards,
Gordon
My solution can tell the difference between clicking Cancel and clicking Ok without entering anything. In both cases, len(t) = 0. When a user clicks Cancel, t is false. If they click Ok with a blank entry, t is the empty string, "". It may not matter in your app though.
Disabling Ok until there is an entry is probably a better way to handle it. I tend to use the VB Script versions, because I've used them before. The QlikView versions are probably better from the user's perspective.