+ Reply to Thread
Results 1 to 8 of 8

Using a cell number instead of a filepath in declaration

  1. #1
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    Using a cell number instead of a filepath in declaration

    I had an idea a while back which I have been unable to resolve and wondered if anyone knew a solution.

    I create funky things that get passed around the office and different people store them in different locations, instead of having to walk around huge offices and changing the code for everyone that uses it I thought I could insert a user form that you can use Application.GetOpenFilename so they can save the document and then enter the file location themselves, which is saved on a hidden sheet in a cell which the code can refer to instead.

    E.g.Instead of declaring a folder location in the code (i.e. Set Filepath = "C:\My Computer\My Location\My Folder") is it possible to enter the filepath into an excel cell (for the example A5) and call A5 within the code rather than the location and still declare it as Filepath.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Using a cell number instead of a filepath in declaration

    Yes, you just refer to the range instead of a literal value:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    Re: Using a cell number instead of a filepath in declaration

    I tried that and it wouldn't work.

    What if the filepath for the spreadsheet has also already been defined?

    i.e.

    Please Login or Register  to view this content.

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Using a cell number instead of a filepath in declaration

    You don't use Set with Strings and you have to specify a worksheet for the range. Note my code versus yours.

  5. #5
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    Re: Using a cell number instead of a filepath in declaration

    So would something like this work?

    BA1 would contain "C:\Users\Scott\Documents\CMC\Database.xlsm"

    Please Login or Register  to view this content.
    Last edited by Sc0tt1e; 10-01-2014 at 05:23 AM.

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Using a cell number instead of a filepath in declaration

    Not quite - this will fail because FPath is a String:
    Please Login or Register  to view this content.
    You need:
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    Re: Using a cell number instead of a filepath in declaration

    Ahhhhhh, you star.

    Cheers Romper, you have just made my life a hell of a lot easier.

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Using a cell number instead of a filepath in declaration

    Glad to help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Trying to get the filepath on "Open", but get filepath of a temporary file instead
    By ianpwilliams in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 08-22-2013, 12:27 AM
  2. [SOLVED] Copying files from a selected filepath to a filepath mentioned in a worksheet's cell
    By subbby in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-10-2012, 03:59 PM
  3. [SOLVED] Copying filepath onto a cell
    By subbby in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-01-2012, 11:43 AM
  4. Replies: 3
    Last Post: 09-24-2010, 04:04 AM
  5. Filepath in cell problem.
    By Gus80 in forum Excel General
    Replies: 2
    Last Post: 03-31-2010, 07:36 PM

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