Results 1 to 3 of 3

Using cell reference as part of file location

This is a discussion on Using cell reference as part of file location within the Excel Questions forums, part of the Question Forums category; I have the following code that I use to retrieve txt files saved in a folder called Text Files: Const ...

  1. #1
    New Member
    Join Date
    Jul 2016
    Posts
    33

    Default Using cell reference as part of file location

    I have the following code that I use to retrieve txt files saved in a folder called Text Files:

    Const fPath As String = "C:\Int\Equal\Game\Open\Text Files"

    There is then further code used to identify and open the files I need, I don't that that is relevant for what im trying to do, which is this:

    I want to have further folders within "Text Files" which will contain the files that I want to open, and reference the name of this folder through cell B2 on a worksheet called "Control". Here is what I have tried but I am getting a compile error:

    Const fPath As String = "C:\Int\Equal\Game\Open\Text Files" & Worksheets("Control").Range("B2") &""

    Appreciate any help.

  2. #2
    Board Regular wideboydixon's Avatar
    Join Date
    Jun 2016
    Location
    Sheffield, UK
    Posts
    1,970

    Default Re: Using cell reference as part of file location

    Hi there,

    The "Const" keyword indicates a constant - i.e. something that can't change according to a cell value. Try this instead:

    Code:
    Dim fPath As String
    fPath = "C:\Int\Equal\Game\Open\Text Files\" & Worksheets("Control").Range("B2").Value
    WBD
    Excel 2016 on Windows 10.
    Please use [code] tags when posting code.
    Please post data in proper tables - see here for some tools.
    Marvin: I've been communicating with the ship.
    Ford: What did it say?
    Marvin: It hates me.


  3. #3
    New Member
    Join Date
    Jul 2016
    Posts
    33

    Default Re: Using cell reference as part of file location

    Thanks, that works great!

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com