Hi all,
I am currently tweeking my VBA for work. In one macro, I've prompted the user to enter the name of the file to open. I've then passed the name into a function that opens it if it is there or display an error message if it is not. I works just fine but I was hoping that a VB pro could tell me if I've done it right. Here is the Function:
Private Function OpenFile(ByVal fName As String) As Boolean
Dim bool As Boolean
Dim wbSource As Workbook
Dim MyPath As String
bool = True
MyPath = ActiveWorkbook.Path
On Error Resume Next
Workbooks.Open (MyPath & "\" & fName)
If Workbooks(fName) Is Nothing Then
MsgBox "File does not exist" & vbNewLine & "Please re-run the the update and enter the proper" & vbNewLine _
& "file name", vbOKOnly, "FILE NOT FOUND"
bool = False
OpenFile = bool
Exit Function
End If
OpenFile = bool
End Function
Once this is passed and returned to my other macros, I have this:
If OpenFile(fName) = False Then Exit Sub
Is this okay?
Any insight will be truly appreciated.
Regards:
Bookmarks