Open file using path and filename data in cell

ourmick

New Member
Joined
Mar 17, 2009
Messages
35
Please
I would like to open files using the data in a single cell.
The cell contains both the file path and the file name. (which can change)

eg cell A1 contains the following

s:\emc1\2009877.csv

how do i open this file using a macro

Cheers
ourmick
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
How the heck? I wanted to know exactly this, and you post and answer in my time frame. The Matrix is at work again.
 
Upvote 0
Thanks Richard
Your code looks for the correct file but for some reason the file can't be seen.
It comes up with runtime error 1004 and says to check the name and path even though the file is definately there.
I am trying to open up a csv file from within excel, does need need any further code??
Thanks
 
Upvote 0
Shouldn't need anything else. What happens if you go to the Immediate Window in the VBE (open up with Ctrl+G if it isn't open) and type in:

?Dir("s:\emc1\2009877.csv")

(or whatever value was in A1). If the file exists this will return the filename "2009877.csv".
 
Upvote 0
You may need to qualify by worksheet or maybe even workbooks as well. Otherwise, it is working from the ActiveWorkbook and ActiveSheet.
Code:
Workbooks.Open Worksheets("Sheet1").Range("A1").Value
 
Upvote 0
Thanks
when i do this nothing is returned?
I've just open the file using normal excel "open" command no problem, just to double check the files ok
Thanks
 
Upvote 0
If you are getting nothing returned by Dir then it suggests that whatever you have in A1 is not a valid path/filename. Check it very carefully against the file's path/name in Explorer.
 
Upvote 0
Sorted!
It was the formatting of the data in the reference cell that was wrong
Cheers for the help:)
 
Upvote 0

Forum statistics

Threads
1,214,804
Messages
6,121,652
Members
449,045
Latest member
Marcus05

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