Mac Calling a File in VBA

polevault139

macrumors 6502
Original poster
Sep 24, 2006
342
0
Illinois
For a class I have to write a program in VBA which involves calling a file. I know the syntax to call the file but I am not sure of the directory. So here is what I have.

Open ("I don't know the directory") For Input As 1

This is probably a really easy question and I am just being oblivious to the answer. So can you please help me with this question.
 

polevault139

macrumors 6502
Original poster
Sep 24, 2006
342
0
Illinois
Well after searching the internet again nothing has come up so could you guys please help or at least say that you don't have any idea. I have Leopard so I don't know if that will make a difference but I don't think so

Anyways here is an updated file path I have tried with the same result

Open ("Macintosh HD/Users/kevinsevers/Documents/Engineering 160/Programming/LeastSqrs.dat") For Input As 1

When I follow my path it goes right to the file so is there just some syntax I am missing?

I get the error Runtime Error : 53 File not Found
 

polevault139

macrumors 6502
Original poster
Sep 24, 2006
342
0
Illinois
Thanks but I double checked all of the grammar and spelling and it all looks good. I've tried with or without spaces, with colons instead of forward slashes, with back slashes. Im just running out of ideas.
 

therevolution

macrumors 6502
May 12, 2003
468
0
Try to keep in mind: you're asking for Windows programming help on a Mac forum. ;)

I don't know VB, but I will take a stab. Try putting a slash before "Macintosh HD" like so:

Open("/Macintosh HD/<etc>")

By the way, how are you running this on Leopard? Mono?
 

polevault139

macrumors 6502
Original poster
Sep 24, 2006
342
0
Illinois
Thanks for your help and I know I was kind of taking a shot in the dark asking for help with VBA on a Mac Forum but thats what we have to learn I want to learn Java but don't know where to start.

I just figured out my problem, I was reading an article about calling a file with OS X and they said the thing about using colon's so I tried it one more time at it finally worked, I think. I haven't actually finished writing the program but at least it didn't give me the file not found error so I think that solved it. Here is what I have now.

Open ("Macintosh HD:Users:myname: Documents:Engineering160:programming:LeastSqrs.dat") for Input as 1

So that seems to work. Thanks for all of the suggestions though, it got me thinking of different ways to try it.

Note: There isnt a space after the colon before Documents but if I didnt do that the simely face would have been there
 

Elkef

macrumors newbie
Mar 12, 2005
11
0
Belgium
Word VBA problem

I have another little problem...

Macintosh HD:Users:elkef:Documents:GG_Test1.docx

This works perfectly... But if I change my harddisk's name, it no longer works...
Anyone knows of a / or ~ alternative?
 

Thom_Edwards

macrumors regular
Apr 11, 2003
240
0
But if I change my harddisk's name, it no longer works
It's been a very long time since I've messed with this kind of thing so I may be completely mistaken, but I seem to remember "startup disk" (or something like that) being used to represent your primary hard drive. Worth a shot, maybe.

EDIT: After some curious googling, I found a page that mentions what I was thinking of. http://www.realgeek.com/forums/vba-file-path-hitch-447214.html. The post is from 2006, so it may be outdated, but it's worth a try I would think.
 
Last edited:

Elkef

macrumors newbie
Mar 12, 2005
11
0
Belgium
Thanks!

This still works!
Const sAScript As String = "Tell application ""Finder""" & _
vbNewLine & "return name of startup disk" & vbNewLine & _
"end tell"
Const sPath As String = ":System Folder:preferences:"
Dim sVolumeName As String
sVolumeName = MacScript(sAScript) & sPath
This is how I get the users shortname and homedir location

ze_path = ze_path + MacScript("(do shell script ""cd ~; pwd | tr '/' ':' "")") + "Documents:"


where tr changes / into :

Together with your hint it works now...
 

chown33

Moderator
Staff member
Aug 9, 2009
8,658
4,903
vertical
The AppleScript to get the current user's home folder is this:
Code:
get path to home folder
If you copy and paste that into AppleScript Editor and run it, you'll see the current complete path beginning with the startup disk.

The path of the startup disk is this:
Code:
get path to startup disk
If you want a Posix path for any of those:
Code:
get Posix path of (path to home folder)
get Posix path of (path to startup disk)
 

Elkef

macrumors newbie
Mar 12, 2005
11
0
Belgium
The AppleScript to get the current user's home folder is this:
Code:
get path to home folder
If you copy and paste that into AppleScript Editor and run it, you'll see the current complete path beginning with the startup disk.

The path of the startup disk is this:
Code:
get path to startup disk
If you want a Posix path for any of those:
Code:
get Posix path of (path to home folder)
get Posix path of (path to startup disk)

Thank you very much, that works... Only now I have an ALIAS in front of the path... Is there a way to eradicate that in Applescript or do I need to do that with a little VBA substring?
 

chown33

Moderator
Staff member
Aug 9, 2009
8,658
4,903
vertical
Thank you very much, that works... Only now I have an ALIAS in front of the path... Is there a way to eradicate that in Applescript or do I need to do that with a little VBA substring?
Code:
get path to startup disk as string

get path to home folder as string

get path to documents folder as string
More "path to xyzzy" folder identifiers:
http://face.centosprime.com/macosxw/applescript-path-to/
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.