• 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.

Show error message when a filename is not "Sample_(month)_(day)"

Hi Everyone,

Do you have any idea on codes that will open a file but will show error message when the filename is not "Sample_(month)_(day)"


I have this but I don't know how to modify it:

filetoopen = Application.GetOpenFilename _
(Title:="Please choose a Report to Parse", _
FileFilter:="")

If filetoopen = False Then
MsgBox "No File Specified.", vbExclamation, "ERROR"
Exit Sub
Else
Set ivr = Workbooks.Open(Filename:=filetoopen)
End If


Also, I am just concerned on the word "Sample_"... The user can open any month or day file... I just need the user to open a file that has a filename "Sample_*". I hope you can help me. Thank you so much!
 
Hi ,

You can check whether the selected file has the desired name format , by using :

filetoopen = Application.GetOpenFilename _
(Title:="Please choose a Report to Parse", _
FileFilter:="")

If filetoopen = False Then
MsgBox "No File Specified.", vbExclamation, "ERROR"
Exit Sub
Else
' This is the additional line of code
If filetoopen like "*Sample_*.xls*" Then
Set ivr = Workbooks.Open(Filename:=filetoopen)
End If
Endif

Narayan
 
Back
Top