Open a workbook from a written path

R

Ricardo Silva

Hi,
I would like to run a macro that would open a workbook in which the path is
written in a cell.
Can someone help me?
Cheers
Ricardo
 
G

Gary Keramidas

one way, but you don't specify if the path has a trailing backslash or not,
whether you want read only or not.
there are a few options.


i just used B3 on sheet1 and my value didn't have a backslash, so i added one
within the code


Sub open_file()
Dim ws As Worksheet
Dim fpath As String

Set ws = Worksheets("Sheet1")
fpath = ws.Range("B3").Value & "\"
Workbooks.Open (fpath & "filename.xls")

End Sub
 
B

Boris

Hi,
I would like to run a macro that would open a workbook in which the path is
written in a cell.
Can someone help me?
Cheers
Ricardo

If path is stored in cell B2 on Sheet1, the macro would contain this:

Workbooks.Open ThisWorkbook.Worksheets("Sheet1").Range("B2").Text

HTH

B.
 
H

HappySenior

If path is stored in cell B2 on Sheet1, the macro would contain this:

Workbooks.Open ThisWorkbook.Worksheets("Sheet1").Range("B2").Text

HTH

B.

Gary and Boris,
I get a subs-script out of range on both proposed solutions. I used
"A20" as my range. Ideas?
Don in Montana
 
D

dan dungan

Hi Don,

It worked for me for Excel 2000 using

Sub openfile()
Workbooks.Open ThisWorkbook.Worksheets("Sheet1").Range("a3").Text
End Sub

Did you change the range to match "A20"?

If so, it sounds like your path is not complete, to me.

Dan
 
B

Boris

Gary and Boris,
I get a subs-script out of range on both proposed solutions. I used
"A20" as my range. Ideas?
Don in Montana

Have you changed "Sheet1" to the name of your worksheet and entered "A20"
as a range?

B.
 
Top