返回列表 上一主題 發帖

EXCEL抓取CSV資料並即時更新

回復 1# jasonwu0114
附上不行的程式碼看看

TOP

不開啟檔案下讀取資料的路徑/檔名設定為變數問題

欲讀取的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
小人物

TOP

        靜思自在 : 多做多得。少做多失。
返回列表 上一主題