Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Using cell reference as part of file location

  1. #1
    New Member
    Join Date
    Jul 2016
    Posts
    34
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    2,102
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    34
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Using cell reference as part of file location

    Thanks, that works great!

User Tag List

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
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.
     


DMCA.com