• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to check if the file selected by the user is correct

ThrottleWorks

Excel Ninja
Hi,


I am preparing a macro, the user has to select multiple files on macro’s prompt.

I am using application.getfile name for selecting file.


The problem is if the user has to select the file “Sachin_loan_details_12578” & he selects something else the results will be wrong.


The file names are not static, they keep changing on daily basis, for example “Sachin_loan_details_12578” , “Sachin_loan_details_78497”.


But the “Sachin_loan_details” part will be static, how do I check that user has opened file with file name starting from “Sachin_loan_details”.


Can anyone help me in this please.
 
Sachin,


Does this work for you?

[pre]
Code:
Dim strFileName As String

strFileName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls*), *.xls*", _
Title:="Select loan detail files", MultiSelect:=False)

If strFileName = "False" Then
MsgBox "No File Selected!", vbExclamation: Exit Sub
Else
If InStr(1, strFileName, "Sachin_loan_details_", vbTextCompare) = 0 Then
MsgBox "You did not choose correct file!", vbCritical: Exit Sub
End If
End If
[/pre]
 
Back
Top