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.

link|improve this question
feedback

2 Answers

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

":Users:Sergey:file.txt"

You can also try:

ThisWorkBook.Path & Application.PathSeparator & "file.txt"
link|improve this answer
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. – Sergey Jul 9 '11 at 4:06
feedback

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/.

link|improve this answer
Henry - thank you so much - I had been struggling with this problem for hours, and it now works. You've made my day! – FarmerGedden Apr 12 at 9:25
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.