[問題] Excel抓取DDE資料

看板Office作者 (龍麟再現風采)時間13年前 (2012/11/05 17:11), 編輯推噓1(104)
留言5則, 3人參與, 最新討論串1/1
軟體:excel 版本:2010 在sheet1的(1,1)會有每秒鐘的動態資料變化 我想把他逐筆存到sheet2裡變成一行 這是我找到的程式碼 可是我執行到 Sheet2.Cells(2, 2) = Sheet2.Cells(2, 2) + 1 '這欄用來記錄現在行數 就出現424執行階段錯誤,此處需要物件 其中Sheet2.Cells(2, 2)一開始我設0 以下是程式碼 Sub Schedule() DoEvents If Sheet2.Cells(2, 1) = 1 Then '當這個欄位值為1的時候開始紀錄 Call record '把DDE值抓到EXCEL的副程式 Call timer_Start 'timer開始 End If End Sub ------------------------------------------------------------------------- Sub timer_Start() '開始timer 每秒call Schedule一次 Application.OnTime Now + TimeValue("00:00:01"), "Schedule", Schedule:=True End Sub -------------------------------------------------------------------------- Sub timer_Stop() On Error Resume Next '停止timer Application.OnTime Now + TimeValue("00:00:01"), "Schedule", Schedule:=False End Sub --------------------------------------------------------------------------- Sub record() '紀錄DDE資料的副程式 Sheet2.Cells(2, 2) = Sheet2.Cells(2, 2) + 1 '這欄用來記錄現在行數 Sheet2.Cells(Sheet2.Cells(2, 2), 3) = Sheet1.Cells(1, 1) '假設DDE要記錄的值在Sheet1的(1,1)這個欄位 '將這資料存在Sheet2中 End Sub ------------------------------------------------------------------------- 感謝各位前輩幫忙!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.135.205.128

11/05 17:27, , 1F
11/05 17:27, 1F

11/05 22:29, , 2F
成功了非常感謝您!!
11/05 22:29, 2F

03/28 18:55, , 3F
20180328來信補上面連結資料
03/28 18:55, 3F

03/28 18:55, , 4F

03/28 23:02, , 5F
S大謝謝
03/28 23:02, 5F
文章代碼(AID): #1GbuAsmH (Office)
文章代碼(AID): #1GbuAsmH (Office)