| 发表于:2007-12-25 17:42:546楼 得分:0 |
retrieving a value from a closed workbook vba does not include a method to retrieve a value from a closed workbook file. you can, however, take advantage of excel's ability to work with linked files. this section contains a custom vba function (getvalue, which follows) that retrieves a value from a closed workbook. it does so by calling an xlm macro, which is an old-style macro used in versions prior to excel 5. fortunately, excel still supports this old macro system. private function getvalue(path, file, sheet, ref) ' retrieves a value from a closed workbook dim arg as string ' make sure the file exists if right(path, 1) <> "\" then path = path & "\" if dir(path & file) = "" then getvalue = "file not found" exit function end if ' create the argument arg = "'" & path & "[" & file & "]" & sheet & "'!" & _ range(ref).range("a1").address(, , xlr1c1) ' EXECute an xlm macro getvalue = EXECuteexcel4macro(arg) end function | | |
|