Open file in VBA on Mac

Beginner!
Having a problem creating a file on Mac using VBA.
I copied the folders pathname but it does not work. Error says – "bad file name or number". I suspect that the problem lies within the pathname, if so what is the right way?

Public Sub task()
Open "/Users/user/test.csv" For Output As file
Close file
End Sub

>Solution :

See this for the docs on Open:
https://docs.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/open-statement

In your case:

Public Sub task()
Open "/Users/user/test.csv" For Output As #1
' do whatever output you need here, then ...
Close #1
End Sub

Because of Apple’s sandboxing, there might be other issues with the file path, but try the above for starters.

Leave a Reply