Reading from a file

G

Guest

I am trying to create a macro which when run in excel sheet, use
GetOpenFilename method to reads a selection of cells from another excel sheet
into a selection of cells within that spreadsheet.

I used the following syntax but it does seem to work (where proj blank
basics is the name oif the sheet)

Any ideas?

filename = Application.GetOpenFilename()
MsgBox filename
If filename = False Then
MsgBox "No file was selected"
Exit Sub
End If
Range("B2").Select
ActiveCell.FormulaR1C1 = _
"='" & filename & "]Proj Plan Basics'!R7C1"
 
B

Bob Phillips

Try this

Filename = Application.GetOpenFilename()
MsgBox Filename
If Filename = False Then
MsgBox "No file was selected"
Exit Sub
End If
ipos = InStrRev(Filename, "\")
Filename = Left(Filename, ipos) & "[" & Right(Filename, Len(Filename) -
ipos) & "]"
Range("B2").FormulaR1C1 = _
"='" & Filename & "Proj Plan Basics'!R7C1"


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top