Public Function PasswordProtected(strFilename As String) As String
Dim dbs As DAO.Database
If Dir(strFilename) = "" Then
PasswordProtected = "File does not exist"
Exit Function
End If
If Right(strFilename, 3) = "mdb" Or Right(strFilename, 5) = "accdb" Then
On Error GoTo ErrorHandler
Set dbs = OpenDatabase(strFilename)
PasswordProtected = "False"
dbs.Close
Exit Function
ElseIf Right(strFilename, 3) = "xls" Or Right(strFilename, 4) = "xlsx" Or Right(strFilename, 4) = "xlsm" Or Right(strFilename, 4) = "xlsb" Then
On Error GoTo ErrorHandler
Set dbs = OpenDatabase(strFilename, True, False, "Excel 5.0")
PasswordProtected = "False"
dbs.Close
Exit Function
Else
PasswordProtected = "File does not exist or incorrect extension"
Exit Function
End If
ErrorHandler:
PasswordProtected = "True"
Exit Function
End Function