- 帖子
- 51
- 主題
- 0
- 精華
- 0
- 積分
- 81
- 點名
- 0
- 作業系統
- Win 7
- 軟體版本
- Office 2010
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2012-3-9
- 最後登錄
- 2013-1-9
|
5#
發表於 2012-3-28 07:45
| 只看該作者
本帖最後由 alexliou 於 2012-3-28 07:50 編輯
也可以利用呼叫excel 提供的 XLM macro來達成.
底下的 GetValue Function有四個引數 :
‧path: 資料所在檔案的路徑 (e.g., "d:\Data\ or d:\Data")
‧file: 活頁簿名稱 (e.g., "Input.xls" or "Input.xlsx)
‧sheet: 工作表名稱 (e.g., "Sheet1")
‧ref: 你所要的值所在儲存格的位址參照 (e.g., "C5")
Private Function GetValue(path, file, sheet, ref)
' 從一個關閉的活頁簿中取資料
Dim arg As String
' 確定檔案存在
If Right(path, 1) <> "\" Then path = path & "\"
If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If
' 設定執行XLM Macro的參數
arg = "'" & path & "[" & file & "]" & sheet & "'!" & Range(ref).Range("A1").Address(, , xlR1C1)
' 執行Microsoft Excel 4.0 巨集
GetValue = ExecuteExcel4Macro(arg)
End Function |
|