- 帖子
- 28
- 主題
- 7
- 精華
- 0
- 積分
- 43
- 點名
- 0
- 作業系統
- windows7
- 軟體版本
- office2010
- 閱讀權限
- 10
- 性別
- 男
- 來自
- 台灣
- 註冊時間
- 2013-11-8
- 最後登錄
- 2020-4-9

|
不開啟檔案下讀取資料的路徑/檔名設定為變數問題
欲讀取的EXCEL檔名中都有當天日期(ex:ooxxx1021216.xls)
想做一張彙總表存放在另一個資料夾
彙總表A欄位是我要的日期
以不開啟檔案方式來讀取資料
有試過直接用 "短期股權投資部位及評價控管表1021216.xls" 是抓到資料
但改成" 短期股權投資部位及評價控管表" & dd & ".xls"
用變數方式就不行
出現要我選取檔案的畫面
應該是變數設定錯誤
請問
1.變數要如何設定??
2.還有其他更方便的方式來讀取未開啟檔案資料??
Sub checkclosedfile1()
Dim strpath As String, strfile As String
Dim strsheet As String, strresult As String
strpath = "X:\風管報表\短期股權投資部位及評價控管表"
strfile = "短期股權投資部位及評價控管表1021202.xls"
strsheet = "全公司I"
strresult = getcellvalue(strpath, strfile, strsheet, "i1")
Cells(2, 2) = strresult
End Sub
Public Function getcellvalue(strpath As String, strfile As String, strsheet As String, stra1 As String)
getcellvalue = ExecuteExcel4Macro("'" & "[" & strfile & "]" & strsheet & "'!" & Range(stra1).Address(, , xlR1C1))
End Function |
|