Option Explicit '' ======================================================== '' Written by Ian O'Connor, CPA '' 22 June 2014 '' http://excelatfinance.com '' email: ioconnor@excelatfinance.com '' '' ======================================================== '' Code 1 ================================================= Sub MBCancel() '' Code 1: Message box Cancel Dim MBButton As Long Dim MBPrompt As String MBPrompt = "PRESS: " & vbNewLine & "YES to continue; NO to Restart, or CANCEL to Exit" '' more code goes here MBButton = MsgBox(MBPrompt, vbYesNoCancel, "xlfStar APP") If MBButton = vbCancel Then Debug.Print "starXLF ============================" Debug.Print "MBButton value: " & MBButton Debug.Print "vbCancel value: " & vbCancel Debug.Print "MB Cancel button pressed at " & Time & vbNewLine Exit Sub End If '' more code goes here End Sub '' Code 2 ================================================= Sub IBCancel_0() '' Code 2: InputBox method Cancel type 0 - a Formula Dim IBdata As String Dim Ans As Double Dim IBPrompt As String IBPrompt = "Enter value " & vbNewLine & "Press OK to continue; or CANCEL to Exit" '' more code goes here IBdata = Application.InputBox(Prompt:=IBPrompt, _ Title:="xlfStar APP", _ Default:="=LN(1.2 / 1.1)", _ Type:=0) If Left(IBdata, 1) <> "=" Then If IBdata = False Then Debug.Print "starXLF ============================" Debug.Print "IB Cancel button pressed at " & Time & vbNewLine Exit Sub End If End If Ans = Evaluate(IBdata) '' more code goes here End Sub '' Code 3 (a) ============================================= Sub IBCancel_1a() '' InputBox method Cancel type 1 - a Number Dim IBdata As Double Dim IBPrompt As String IBPrompt = "Enter value " & vbNewLine & "Press OK to continue; or CANCEL to Exit" '' more code goes here IBdata = Application.InputBox(Prompt:=IBPrompt, _ Title:="xlfStar APP", _ Default:=123.45, _ Type:=1) If IBdata = False Then Debug.Print "starXLF ============================" Debug.Print "IB Cancel button pressed at " & Time & vbNewLine Exit Sub End If '' more code goes here End Sub '' Code 3 (b) ============================================= Sub IBCancel_1b() '' InputBox method Cancel type 1 - a Number Dim IBdata As Variant Dim IBPrompt As String IBPrompt = "Enter value " & vbNewLine & "Press OK to continue; or CANCEL to Exit" '' more code goes here IBdata = Application.InputBox(Prompt:=IBPrompt, _ Title:="xlfStar APP", _ Default:=123.45, _ Type:=1) If IBdata = False And TypeName(IBdata) = "Boolean" Then Debug.Print "starXLF ============================" Debug.Print "IB Cancel button pressed at " & Time & vbNewLine Exit Sub End If '' more code goes here End Sub '' Code 4 ================================================= Sub IBCancel_2() '' InputBox method Cancel type 2 - Text (a String) Dim IBdata As String Dim IBPrompt As String IBPrompt = "Enter value " & vbNewLine & "Press OK to continue; or CANCEL to Exit" '' more code goes here IBdata = Application.InputBox(Prompt:=IBPrompt, _ Title:="xlfStar APP", _ Default:="ANZ.AX", _ Type:=2) If IBdata = False Then Debug.Print "starXLF ============================" Debug.Print "IB Cancel button pressed at " & Time & vbNewLine Exit Sub End If '' more code goes here End Sub '' Code 5 ================================================= Sub IBCancel_4() '' InputBox method Cancel type 4 - a Logical value (True or False) Dim IBdata As Boolean Dim IBPrompt As String IBPrompt = "Enter value " & vbNewLine & "Press OK to continue; or CANCEL to Exit" '' more code goes here IBdata = Application.InputBox(Prompt:=IBPrompt, _ Title:="xlfStar APP", _ Default:=True, _ Type:=4) If IBdata = False Then Debug.Print "starXLF ============================" Debug.Print "IB returned FALSE at " & Time Debug.Print "Note: it is not possible to distinguish between an" Debug.Print "entered False and the Cancel return value of False" & vbNewLine '' Exit Sub End If '' more code goes here End Sub '' Code 6 ================================================== Sub IBCancel_8() '' InputBox method Cancel type 8 - a Cell Reference (as a Range object) Dim IBdata As Range Dim IBPrompt As String IBPrompt = "Enter range " & vbNewLine & "Press OK to continue; or CANCEL to Exit" '' more code goes here On Error Resume Next Set IBdata = Application.InputBox(Prompt:=IBPrompt, _ Title:="xlfStar APP", _ Default:="$A$1:$B$4", _ Type:=8) If IBdata Is Nothing Then Debug.Print "starXLF ============================" Debug.Print "IB Cancel button pressed at " & Time & vbNewLine Exit Sub End If '' more code goes here End Sub '' Code 7 ================================================= Sub IBCancel_16() '' InputBox method Cancel type 16 - An Error value Dim IBdata As Variant Dim IBPrompt As String Dim tmp IBPrompt = "Enter ERROR value: " & vbNewLine & "Press OK to continue; or CANCEL to Exit" '' more code goes here '' Error code: #N/A = 2042 IBdata = Application.InputBox(Prompt:=IBPrompt, _ Title:="xlfStar APP", _ Default:="#N/A", _ Type:=16) If Not IsError(IBdata) Then If IBdata = False Then Debug.Print "xlfSTAR ============================" Debug.Print "IB Cancel button pressed at " & Time & vbNewLine Exit Sub End If End If '' more code goes here End Sub '' Code 8 ================================================= Sub IBCancel_64() '' InputBox method Cancel type 64 - an Array of values Dim IBdata As Variant Dim IBPrompt As String IBPrompt = "Enter array constant, or select worksheet array: " & vbNewLine & "Press OK to continue; or CANCEL to Exit" '' more code goes here IBdata = Application.InputBox(Prompt:=IBPrompt, _ Title:="xlfStar APP", _ Default:="{11,12,13;21,22,23}", _ Type:=64) If Not IsArray(IBdata) Then If IBdata = False Then Debug.Print "starXLF ============================" Debug.Print "IB Cancel button pressed at " & Time & vbNewLine Exit Sub End If End If '' more code goes here End Sub