Opening a file for output/input in Microsoft Visual Basic on Mac OS X

10,479

Solution 1

You have to retrace the path back to the hard disk. If I run

Open "testfile.txt" For Output As 1

the new file appears in /Applications/Microsoft Office 2004/Templates/

If I retrace back to the hard disk with

Open "..:..:..:Users:henrywhitney:Documents:Scribe:Macro Data:testfile.txt" For Output As 1

it appears in /Users/henrywhitney/Documents/Scribe/Macro Data/.

Solution 2

Did you try to use : instead of /? Something like

":Users:Sergey:file.txt"

You can also try:

ThisWorkBook.Path & Application.PathSeparator & "file.txt"
Share:
10,479

Related videos on Youtube

Sergey
Author by

Sergey

http://www.snevsky.com

Updated on September 18, 2022

Comments

  • Sergey
    Sergey almost 2 years

    I am working in Excel for Mac 2011 and my goal is to create a simple macro that writes particular cells to a file. This is generally a simple task, but VB chooses not to accept a file path. For example, the following code literally writes a file called ~/file.txt, ignoring the directory structure entirely:

    Open "~/file.txt" For Output As #1
    

    I have tried the full path /Users/Sergey/file.txt to no avail.

  • Sergey
    Sergey almost 13 years
    The former came up with an error: "Path not found." The latter worked out fine, however working relative to the excel document is not always the ideal scenario. For my purpose here, it did the job.
  • FarmerGedden
    FarmerGedden about 12 years
    Henry - thank you so much - I had been struggling with this problem for hours, and it now works. You've made my day!
  • Sridhar Sarnobat
    Sridhar Sarnobat over 5 years
    Thank you, this was my issue. Note: using Debug.Print ThisWorkbook.Path helps a lot.