Using cell reference as part of file location

gt213

Board Regular
Joined
Jul 5, 2016
Messages
61
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.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
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
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top