I want to open a simple workbook from a little macro with the VBA of Excel 16 on a MAC 10.10 but I can't.
I have my macro:
Sub Test()
Call Workbooks.Open("Classeur1.xlsm")
End Sub
With Office 11, this function works fine but I have an error with Office 16:
Run-time error '1004':
Application-defined or object-defined error
Do you have any idea to fix it please?
wbName = "FILENAME"
If CInt(Split(Application.Version, ".")(0)) >= 15 Then 'excel 2016 support
wbName = Replace(wbName, ":", "/")
wbName = Replace(wbName, "Macintosh HD", "", Count:=1)
End If
Check Excel Version and then replace characters accordingly. I'm not sure why, but my Excel 2016 on macOS is of version 15.xx
The problem is Excel 2016 for Mac has a strange "default" directory that it works in. Mine starts up in /Users/xxxxx/Library/Containers/com.microsoft.Excel/Data
. You therefore need the fully qualified path to your workbook. Example:-
Sub Test()
Call Workbooks.Open("/Users/damien/Documents/Classeur1.xlsm")
End Sub
Just a side note, you do not need to use the Call
statement. You could simply do this:-
Sub Test()
Workbooks.Open "/Users/damien/Documents/Classeur1.xlsm"
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With