'********************************************************************************************************** ' Name: isEmptyString ' Author: mielk | 2014-09-20 ' ' Description: Function to check if the given value is empty string. ' Note that strings consisting only of blank characters (i.e. spaces) are also ' considered to be an empty string. ' ' Parameters: ' value Value to be checked. ' ' ' Returns: ' Boolean True - if the given value is empty or cannot be converted to String type. ' True value is returned in a few cases: ' * the source parameter [value] is an empty string, ' * the source parameter [value] is a string consisting only of blank characters, ' * the source parameter [value] is not a string and cannot be converted into ' string (i.e it is object or array). ' False - if the given value is a non-empty string or other primitive value that can ' be converted into String. ' ' ' ' --- Changes log ----------------------------------------------------------------------------------------- ' 2014-09-20 mielk Function created. '********************************************************************************************************** Public Function isEmptyString(ByVal value As Variant) As Boolean Const METHOD_NAME As String = "isEmptyString" '------------------------------------------------------------------------------------------------------ 'First check if the given value can be converted into String. If not, function should return --------| 'True, so the code moves to the [NotStringException] label, change the value of function to '| 'True and leaves the function. '| On Error GoTo NotStringException '| value = VBA.CStr(value) '| On Error GoTo 0 '| '----------------------------------------------------------------------------------------------------| 'Check different cases when the function should return True. ----------------------------------------| If VBA.IsMissing(value) Then '| isEmptyString = True '| ElseIf VBA.isEmpty(value) Then '| isEmptyString = True '| ElseIf VBA.Len(VBA.Trim(value)) = 0 Then '| isEmptyString = True '| End If '| '----------------------------------------------------------------------------------------------------| '========================================================================================================== ExitPoint: Exit Function '---------------------------------------------------------------------------------------------------------- NotStringException: isEmptyString = True GoTo ExitPoint End Function