简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM