+ Reply to Thread
Results 1 to 7 of 7

Get rid of driveletter in filepath *Help needed*

  1. #1
    Registered User
    Join Date
    07-24-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2003
    Posts
    69

    Get rid of driveletter in filepath *Help needed*

    Hi all

    I really need the solution to this problem.

    My excel program sometimes need to open a file at for example this path:

    E:\spid\data\pictures\picture.jpg - and thats all fine but how can i get rid of the need to specify driveletter?

    If other users of the program save the spid-program on their f: drive ,, k:drive or whatever driveletter other than e: - my path/paths in the program doesnt work anymore :/

    Are there any way to program that my excel program should use the folder of which the program itself lies in, as root folder ? So the program will work no matter which drive the folder lies on ?
    So the path afterwards only would be \data\pictures\picture.jpg. For example ?
    I have already tried \\data\pictures\picture.jpg - that doesnt work.


    My folder SPID contains the excel file (spid.xls) in its root and thats the only programfile in that folder furthermore i have different folders inside the SPID folder like "pictures" , "texts" and "url" . These folders contain only things that is being called to spid.xls whenever needed... To show picture / show text or read an url for going to a website.


    Can this be done ? Like creating a universal path ?

    Thanks in advance

    /Jan
    Last edited by Lkivagten; 07-30-2012 at 12:47 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Get rid of driveletter in filepath *Help needed*

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    07-24-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Get rid of driveletter in filepath *Help needed*

    Hi SHG

    i Have tried your code and have changed what i thought should be changed to fit my code... but unfortunately it doesnt work :\.

    I have changed your "bob.xls" to "spid.xls" and this part must be right i guess.
    i have changed my filepaths in the code from (example) "e:\spid\data\pictures\" & ComboBox1.Value & ".jpg" to just: "\data\pictures\" & ComboBox1.Value & ".jpg"

    Before your code was inserted i had already other "dim as string" and i dont know if these should be deleted or stay?
    If i start the program with your code (with my changes) and my code from before i either get "spid is already running, will you run spid again"?
    if i say yes spid starts again and i think that IF i had saved the code with the new changes the program would maybe have looped. I didnt save it and when spid is run again im back to the "old" excisting code without your code.

    If i say no i get an error.

    I have uploaded a text file with my code.. can you ? or anyone else who takes time to look into this,, see what is wrong?

    Thank you

    /Jan
    Attached Files Attached Files
    Last edited by Lkivagten; 07-30-2012 at 05:13 PM.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Get rid of driveletter in filepath *Help needed*

    The code was just to show how to open a file using a path relative to the workbook. I know you were trying to do something with a picture, but had no idea what.

    You code, at a glance, should be something like

    Please Login or Register  to view this content.
    Why post a Word doc instead of a workbook?

  5. #5
    Registered User
    Join Date
    07-24-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Get rid of driveletter in filepath *Help needed*

    Hi SHG

    I have tried to upload my xls file before but without the belonging files (and that folder is too big to upload) another user couldnt get the file to work..it looped for him. But ill give it a go -

    Could you help me replace,insert or delete whats needed to get the relative path function to work ? i have 3 different "jobs" in the same category.
    1 to show picture in image2 box (e:\spid\data\billeder\stationsbilleder\*.jpg)
    2 to read textfile for info and show that info in textbox5 (e:\spid\data\tekst\*.txt)
    3 to read textfile for url and go to that url. (e:\spid\data\url\*.txt)

    The "read textdocuments function is at the bottom of spid userform code..i dont know if this is affected by your code and/or need to be changed?

    Thanks

    /Jan
    Attached Files Attached Files

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Get rid of driveletter in filepath *Help needed*

    You're overcomplicating this.

    Assuming your code works when you have a local mapped drive, and the files you open are all in the same directory as the workbook, then go back to your original code, and replace as much of this

    "K:\spid\spid\Data\Tekst\"

    as you need with ThisWorkbook.Path & "\"

    So if the workbook is in "K:\spid\spid\Data", then the string above should be

    ThisWorkbook.Path & "\Tekst"

    If the workbook is in "K:\spid\spid\", then the string above should be

    ThisWorkbook.Path & "\spid\Tekst"

    If the workbook is in "K:\spid\", then the string above should be

    ThisWorkbook.Path & "\spid\spid\Tekst"
    Last edited by shg; 07-31-2012 at 06:24 AM.

  7. #7
    Registered User
    Join Date
    07-24-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Get rid of driveletter in filepath *Help needed*

    Thank you HSG

    Maybe i was overcomplicating this..but i havent worked with those workbook.Spath and the like before.

    In your previous code you wrote Workbooks.open spath.. and that confused me a little .
    Ill try to sort it out on my own from here.
    thanks again

    /Jan

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1