Consider the following code below. This code stores the filename the user returns in the public variable Fname. If the file is already open, then the sub will not open the file again and if the user cancels the filename procedure then the sub exits
Code:
Public Fname
Sub OpenF()
Dim wb As Workbook
Fname = Application.GetOpenFilename("Excel-files,*.xls", , "Please open your file")
'no file selected
If Fname = False Then Exit Sub
For Each wb In Application.Workbooks
If wb.Path & "\" & wb.Name = Fname Then
MsgBox "File " & wb.Name & " is already open"
Exit Sub
End If
Next
Workbooks.Open (Fname)
End Sub
Bookmarks