Calling a File in VBA

Discussion in 'Mac Programming' started by polevault139, Oct 28, 2007.

  1. macrumors 6502

    Joined:
    Sep 24, 2006
    Location:
    Illinois
    #1
    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.
     
  2. thread starter macrumors 6502

    Joined:
    Sep 24, 2006
    Location:
    Illinois
    #2
    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
     
  3. macrumors 6502a

    Joined:
    Aug 13, 2007
    Location:
    Not where you live.
    #3
    I don't really have the answer apart from reminding you that OSX is case sensitive?

    Sorry, that's the best I can come up with.

    Cheers.
     
  4. thread starter macrumors 6502

    Joined:
    Sep 24, 2006
    Location:
    Illinois
    #4
    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.
     
  5. macrumors 6502

    Joined:
    May 12, 2003
    #5
    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?
     
  6. thread starter macrumors 6502

    Joined:
    Sep 24, 2006
    Location:
    Illinois
    #6
    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
     
  7. macrumors 6502a

    Joined:
    Aug 13, 2007
    Location:
    Not where you live.
    #7
    Good job on figuring it out.

    It's always helpful to bounce stuff off others when you're stuck.

    Cheers.
     
  8. macrumors newbie

    Joined:
    Mar 12, 2005
    Location:
    Belgium
    #8
    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?
     
  9. Thom_Edwards, Jul 1, 2011
    Last edited: Jul 1, 2011

    macrumors regular

    Joined:
    Apr 11, 2003
    #9
    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.
     
  10. macrumors newbie

    Joined:
    Mar 12, 2005
    Location:
    Belgium
    #10
    Thanks!

    This still works!
    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...
     
  11. macrumors 603

    Joined:
    Aug 9, 2009
    #11
    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)
    
     
  12. macrumors newbie

    Joined:
    Mar 12, 2005
    Location:
    Belgium
    #12

    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?
     
  13. chown33, Jul 2, 2011
    Last edited: Jul 2, 2011

    macrumors 603

    Joined:
    Aug 9, 2009
    #13
    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/
     
  14. macrumors newbie

    Joined:
    Mar 12, 2005
    Location:
    Belgium

Share This Page