Input data validation is one of the most important activity in report generation process. Which will help user to avoid run time issues while performing report generation tasks. Thus, it is very vital to have input in proper format. To identify file could be a one of validation activity while automation the project.
This can be achieve with a small VBA function which will be used to identify if file is excel.
Here is the VBA Function which will return true value if input file is excel:
Function isExcel(ByVal FileName As String)
If UCase(Right(FileName, 3)) = "XLS" Or UCase(Right(FileName, 4)) = "XLSX" Or
UCase(Right(FileName, 4)) = "XLSM" Or UCase(Right(FileName, 4)) = "XLSB" Then
isExcel = True
MsgBox "File is Excel workbook"
Else
isExcel = False
MsgBox "File is not a Excel workbook"
End If
End Function
As soon as you write above function in module. Then you can used this function in formula bar of you excel file where you write this function. You need to provide complete path of input file. Based on your file extension function will return True or False.
This can be achieve with a small VBA function which will be used to identify if file is excel.
Here is the VBA Function which will return true value if input file is excel:
Function isExcel(ByVal FileName As String)
' Author: Dreams24
' Written for VBA Tricks and tips blog
UCase(Right(FileName, 4)) = "XLSM" Or UCase(Right(FileName, 4)) = "XLSB" Then
isExcel = True
MsgBox "File is Excel workbook"
Else
isExcel = False
MsgBox "File is not a Excel workbook"
End If
End Function
As soon as you write above function in module. Then you can used this function in formula bar of you excel file where you write this function. You need to provide complete path of input file. Based on your file extension function will return True or False.
No comments:
Post a Comment