ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Getafile from Cellref Path (https://www.excelbanter.com/excel-programming/384038-getafile-cellref-path.html)

CLR

Getafile from Cellref Path
 
Hi All..........

I'm trying to open a workbook from a Path that is subject to change, and is
therefore entered by the user in cell MainMenu!H30. I've tried this, with
the Path in the referenced cell, but no joy.

Workbooks.Open FileName:=Range("MainMenu!h30").Value & "\MyFileName.XLS"

I get a pop-up saying that the correct path and filename "could not be found".
but if I hardcode the same path and filename it works fine


Any help would be much appreciated.

Vaya con Dios,
Chuck, CABGx3



Tom Ogilvy

Getafile from Cellref Path
 
no reason it wouldn't work if it produces the same string. Test it and see

Dim s as String
s = Range("MainMenu!h30").Value & "\MyFileName.XLS"
msgbox s '<== optional, but useful until you have it working
if dir(s) < "" then
Workbooks.Open FileName:= s
else
msgbox s & " Not found"
End if

Assumes this code is not in a sheet module rather than a general module and
it isn't within the scope of an on error resume next statement. If so, you
might try

s = Application.Range("MainMenu!h30").Value & "\MyFileName.XLS"

--
Regards,
Tom Ogilvy

"CLR" wrote:

Hi All..........

I'm trying to open a workbook from a Path that is subject to change, and is
therefore entered by the user in cell MainMenu!H30. I've tried this, with
the Path in the referenced cell, but no joy.

Workbooks.Open FileName:=Range("MainMenu!h30").Value & "\MyFileName.XLS"

I get a pop-up saying that the correct path and filename "could not be found".
but if I hardcode the same path and filename it works fine


Any help would be much appreciated.

Vaya con Dios,
Chuck, CABGx3



CLR

Getafile from Cellref Path
 
Ok Tom, that did the trick....using your testing hints, I eventually found
that my test-shortcut of using ThisWorkBook.Path did not work so well, and
when I finally put a real path in H30, all went well.

Thanks for straightening me out.........

Vaya con Dios,
Chuck, CABGx3




"Tom Ogilvy" wrote:

no reason it wouldn't work if it produces the same string. Test it and see

Dim s as String
s = Range("MainMenu!h30").Value & "\MyFileName.XLS"
msgbox s '<== optional, but useful until you have it working
if dir(s) < "" then
Workbooks.Open FileName:= s
else
msgbox s & " Not found"
End if

Assumes this code is not in a sheet module rather than a general module and
it isn't within the scope of an on error resume next statement. If so, you
might try

s = Application.Range("MainMenu!h30").Value & "\MyFileName.XLS"

--
Regards,
Tom Ogilvy

"CLR" wrote:

Hi All..........

I'm trying to open a workbook from a Path that is subject to change, and is
therefore entered by the user in cell MainMenu!H30. I've tried this, with
the Path in the referenced cell, but no joy.

Workbooks.Open FileName:=Range("MainMenu!h30").Value & "\MyFileName.XLS"

I get a pop-up saying that the correct path and filename "could not be found".
but if I hardcode the same path and filename it works fine


Any help would be much appreciated.

Vaya con Dios,
Chuck, CABGx3




All times are GMT +1. The time now is 03:54 PM.

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