K
kuansheng
Hi Guys,
I happen to come across this codes from www.exceltip.com. I am
wondering whether is there a way to create a user form that can prompt
user to enter or select the name of the file of th e closed workbook
and worksheet that we they want to get the data from. The following is
the code that will get value from a closed workbook. But the problem is
that the file name of the closed workbook and worksheet is hard coded.
What i need is for the user to enter those information. I hope someone
can hel me out in this.
Sub test()
GetValuesFromAClosedWorkbook "C:", "Book1.xls", _
"Sheet1", "A1:K30"
End Sub
Sub GetValuesFromAClosedWorkbook(fPath As String, _
fName As String, sName, cellRange As String)
With ActiveSheet.Range(cellRange)
.FormulaArray = "='" & fPath & "\[" & fName & "]" _
& sName & "'!" & cellRange
.Value = .Value
End With
End Sub
I happen to come across this codes from www.exceltip.com. I am
wondering whether is there a way to create a user form that can prompt
user to enter or select the name of the file of th e closed workbook
and worksheet that we they want to get the data from. The following is
the code that will get value from a closed workbook. But the problem is
that the file name of the closed workbook and worksheet is hard coded.
What i need is for the user to enter those information. I hope someone
can hel me out in this.
Sub test()
GetValuesFromAClosedWorkbook "C:", "Book1.xls", _
"Sheet1", "A1:K30"
End Sub
Sub GetValuesFromAClosedWorkbook(fPath As String, _
fName As String, sName, cellRange As String)
With ActiveSheet.Range(cellRange)
.FormulaArray = "='" & fPath & "\[" & fName & "]" _
& sName & "'!" & cellRange
.Value = .Value
End With
End Sub