ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   macro that opens file named in cell doesnt work (https://www.excelbanter.com/excel-worksheet-functions/166164-macro-opens-file-named-cell-doesnt-work.html)

Illuminati

macro that opens file named in cell doesnt work
 
I wrote a macro that should open file with the name specified in cell
B8. It worked well yesterday but today I opened the file and the macro
doesnt work at all.

Could anyone tell whats wrong with the code.

Here it is the code:

Sub Import()

Sheets("Instruction").Select
Range("B8").Select
filetext = Selection.Value & ".xls"
directory = ".\"
Workbooks.Open directory & filetext

End Sub


Gary''s Student

macro that opens file named in cell doesnt work
 
Try setting directory to the full path.
--
Gary''s Student - gsnu2007a


"Illuminati" wrote:

I wrote a macro that should open file with the name specified in cell
B8. It worked well yesterday but today I opened the file and the macro
doesnt work at all.

Could anyone tell whats wrong with the code.

Here it is the code:

Sub Import()

Sheets("Instruction").Select
Range("B8").Select
filetext = Selection.Value & ".xls"
directory = ".\"
Workbooks.Open directory & filetext

End Sub



Illuminati

macro that opens file named in cell doesnt work
 
On 15 Lis, 12:15, Gary''s Student
wrote:
Try setting directory to the full path.
--
Gary''s Student - gsnu2007a


But I need this macro to open file from folder that the file with
macro is.
Btw, I have tried to put the name of the folder but it still doesn't
work.
It works when I put the exact path of the file with the name (not
reffering to the cell).

Please help, I have tried to modify the code and put sth like this:
Workbooks.Open Filename:= _
".\" & Range("B8").Value & ".xls"
But the error is still the same:
run-time error '1004'


All times are GMT +1. The time now is 12:23 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com