I'm new to Excel VBA. In a new workbook (macro_tester.xlsm) I created a new Module1 and put this code into it:
Public Function fileopen(f)
Dim wbk As Workbook
file = f
If Dir(file) = "" Then
fileopen = "File '" & file & "' Not Found"
Exit Function
End If
Set wbk = Workbooks.Open(file)
If wbk Is Nothing Then
fileopen = "File '" & file & "' Failed To Open"
Exit Function
End If
End Function
I created an empty Excel file called test.xlsx and it is on a USB drive D:. No matter what I do, I always get the message "File 'D:\test.xlsx' Failed To Open". The file is found but not opened.
I've used fully qualified pathnames to the local directory, I've used a USB drive with the file in the root. And I've made sure that the target file is not open (just the one with the macro in it). I've also tried to open other Excel files. I can't get any file to open.
Any suggestions would be appreciated.