- 帖子
- 161
- 主題
- 26
- 精華
- 0
- 積分
- 187
- 點名
- 0
- 作業系統
- xp
- 軟體版本
- office 2010
- 閱讀權限
- 20
- 性別
- 男
- 來自
- TW
- 註冊時間
- 2011-1-2
- 最後登錄
- 2025-10-9
|
回復 16# GBKEE
請教 G 大大
我改了一些資料 有些資料還收不到
請 G 大 看那裡要改的
謝謝- Dim ie As Object '模組最頂端 Dim 供這模組的程序使用的變數
- Sub AllFile()
- Dim i As Integer, v, Y As Integer, S As String
- Set ie = CreateObject("internetexplorer.application") '使用此方式可以免除 "設定引用項目"
- With ie '縮小IE視窗
- .Visible = True
- .Width = 5
- .Height = 5
- End With
- With 工作表1
- Dim AR
- AR = .Range("E1:G1")
- .Range("E:G") = ""
- .Range("E1:G1") = AR
- ' .Range("E2").CurrentRegion = "" '清除工作表1,年度範圍
- For i = 2 To .Range("A" & .Rows.Count).End(xlUp).Row
- v = .Cells(i, 1).Value
- GetDividend (v)
- .Cells(i, 5).Value = 工作表2.Cells(2, 2).Value
- .Cells(i, 6).Value = 工作表2.Cells(2, 5).Value
- GetClosePrice (v)
- .Cells(i, 7).Value = 工作表3.Cells(2, 8).Value
-
- Next
- End With
- With ie 'IE視窗最大化
- Application.WindowState = xlMaximized
- .Height = Application.Height
- .Width = Application.Width
- .Quit
- End With
- End Sub
- 'Private Sub GetDividend(ByVal ss As String)
- Private Sub GetDividend(ByVal ss As String) '取股利網頁
- Dim rr As String, T As Date, i, ii, k, j, S As Object
- 'On Error Resume Next '程式的執行沒有預期的錯誤,此行可不用.
- T = Time
- rr = "http://dj.mybank.com.tw/z/zc/zcc/zcc_" & ss & ".asp.htm"
- With ie
- .Navigate rr
- Do While .readyState <> 4 '等待網頁下載完畢
- DoEvents
- If Time >= T + #12:00:03 AM# Then '等待8秒 3秒太少會誤錯改8妙
- DoEvents
- Application.SendKeys "~" '股票代號錯誤,網頁會有訊息,須按確定,才可繼續下面股票代號
-
- Exit Do
- End If
- Loop
- ''***不是等待8秒 3秒太少會誤錯改8妙 ***
- Do
- Set S = .Document.getElementsByTagName("table")(3) ' 新的 table 4
- Loop Until Not S Is Nothing
- '*** 勝一 沒捉到 ????
- '*** 因程式運行太快 , S Is Nothing, S 尚未指定為.Document.getElementsByTagName("table")(4)
- '*** 程式已經執行下一行, With 工作表2 的程式碼
- With 工作表2
- .UsedRange.Clear
- For i = 0 To S.Rows.Length - 1 '寫入資料
- k = k + 1
- 'For j = 0 To S.Rows(i).Length - 1 '這行是錯誤的 也是多餘的迴圈
- '用 On Error Resume Next 使程式繼續執行
- For ii = 0 To S.Rows(i).Cells.Length - 1 ' S.Rows(i).Cells.Length - 1 才是正確
- .Cells(k, ii + 1) = S.Rows(i).Cells(ii).innerText
- DoEvents
- Next
- 'Next
- Next
- End With
- End With
- End Sub
- Private Sub GetClosePrice(ByVal ss As String) ' 取收盤價網頁
- Dim rr As String, T As Date, i, ii, k, j, S As Object
- 'On Error Resume Next '程式的執行沒有預期的錯誤,此行可不用.
- T = Time
- rr = "https://djinfo.cathaysec.com.tw/Z/ZC/ZCX/ZCXNEWCATHAYSEC.DJHTM?A=" & ss
- With ie
- .Navigate rr
- Do While .readyState <> 4 '等待網頁下載完畢
- DoEvents
- If Time >= T + #12:00:03 AM# Then '等待8秒 3秒太少會誤錯改8妙
- DoEvents
- Application.SendKeys "~" '股票代號錯誤,網頁會有訊息,須按確定,才可繼續下面股票代號
-
- Exit Do
- End If
- Loop
- ''***不是等待8秒 3秒太少會誤錯改8妙 ***
- Do
- Set S = .Document.getElementsByTagName("table")(2) ' 新的 table 4
- Loop Until Not S Is Nothing
- '*** 勝一 沒捉到 ????
- '*** 因程式運行太快 , S Is Nothing, S 尚未指定為.Document.getElementsByTagName("table")(4)
- '*** 程式已經執行下一行, With 工作表2 的程式碼
- With 工作表3
- .UsedRange.Clear
- For i = 0 To S.Rows.Length - 1 '寫入資料
- k = k + 1
- 'For j = 0 To S.Rows(i).Length - 1 '這行是錯誤的 也是多餘的迴圈
- '用 On Error Resume Next 使程式繼續執行
- For ii = 0 To S.Rows(i).Cells.Length - 1 ' S.Rows(i).Cells.Length - 1 才是正確
- .Cells(k, ii + 1) = S.Rows(i).Cells(ii).innerText
- DoEvents
- Next
- 'Next
- Next
- End With
- End With
- End Sub
複製代碼
|
-
-
配息測試-3.rar
(29.12 KB)
|