- 帖子
- 161
- 主題
- 26
- 精華
- 0
- 積分
- 187
- 點名
- 0
- 作業系統
- xp
- 軟體版本
- office 2010
- 閱讀權限
- 20
- 性別
- 男
- 來自
- TW
- 註冊時間
- 2011-1-2
- 最後登錄
- 2025-10-9
|
7#
發表於 2019-1-15 21:13
| 只看該作者
放棄了還是找不到原因,用 GBKEE 超版大大 msxml2.xmlhttp 的方法可以用了,謝謝
http://forum.twbts.com/thread-21270-1-2.html- Option Explicit
- 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:M1")
- .Range("E:M") = ""
- .Range("E1:M1") = AR
- ' .Range("E2").CurrentRegion = "" '清除工作表1,年度範圍
- For i = 2 To .Range("A" & .Rows.Count).End(xlUp).Row
- v = .Cells(i, 1).Value
- '''''
- GetDividend (v)
- GetClosePrice (v)
- GetIncome (v)
- GetBalance (v)
- GetShareholding (v)
- .Cells(i, 5).Value = 工作表2.Cells(5, 2).Value
- .Cells(i, 6).Value = 工作表2.Cells(5, 3).Value
- .Cells(i, 7).Value = 工作表3.Cells(2, 8).Value
- .Cells(i, 8).Value = .Cells(i, 5).Value / .Cells(i, 7).Value '現金殖利率
- On Error Resume Next
- ' .Cells(i, 8).NumberFormatLocal = "0.00%"
- .Cells(i, 9).Value = 工作表4.Cells(66, 2).Value / 工作表5.Cells(94, 2).Value 'ROE%
- On Error Resume Next
- .Cells(i, 10).Value = 工作表3.Cells(4, 2).Value '本益比
- .Cells(i, 11).Value = 工作表3.Cells(12, 4).Value '股價淨值比
- .Cells(i, 12).Value = 工作表3.Cells(11, 4).Value '負債比%
- ' .Cells(i, 12).NumberFormatLocal = "0.00%"
- .Cells(i, 13).Value = 工作表6.Cells(3, 4).Value '董監持股%
- ' .Cells(i, 13).NumberFormatLocal = "0.00%"
- Debug.Print v
- Next
- End With
- With ie 'IE視窗最大化
- Application.WindowState = xlMaximized
- .Height = Application.Height
- .Width = Application.Width
- .Quit
- End With
- End Sub
- Public Function MyFile(v As Integer, i As Integer)
- ' 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
- .Range("E" & v & ":M" & v) = ""
- ' .Range("E2").CurrentRegion = "" '清除工作表1,年度範圍
- v = .Cells(i, 1).Value
- GetDividend (v)
- GetClosePrice (v)
- GetIncome (v)
- GetBalance (v)
- GetShareholding (v)
- .Cells(i, 5).Value = 工作表2.Cells(5, 2).Value
- .Cells(i, 6).Value = 工作表2.Cells(5, 3).Value
- .Cells(i, 7).Value = 工作表3.Cells(2, 8).Value
- .Cells(i, 8).Value = .Cells(i, 5).Value / .Cells(i, 7).Value '現金殖利率
- On Error Resume Next
- ' .Cells(i, 8).NumberFormatLocal = "0.00%"
- .Cells(i, 9).Value = 工作表4.Cells(66, 2).Value / 工作表5.Cells(94, 2).Value 'ROE%
- On Error Resume Next
- .Cells(i, 10).Value = 工作表3.Cells(4, 2).Value '本益比
- .Cells(i, 11).Value = 工作表3.Cells(12, 4).Value '股價淨值比
- .Cells(i, 12).Value = 工作表3.Cells(11, 4).Value '負債比%
- ' .Cells(i, 12).NumberFormatLocal = "0.00%"
- .Cells(i, 13).Value = 工作表6.Cells(3, 4).Value '董監持股%
- ' .Cells(i, 13).NumberFormatLocal = "0.00%"
- End With
- With ie 'IE視窗最大化
- Application.WindowState = xlMaximized
- .Height = Application.Height
- .Width = Application.Width
- .Quit
- End With
- End Function
- Private Sub GetDividend(ByVal ss As String) '取股利網頁
- Dim strText As String
- Dim i As Integer, j As Integer, xTable As Object
- With CreateObject("msxml2.xmlhttp")
- .Open "GET", "http://pscnetinvest.moneydj.com.tw/z/zc/zcc/zcc_" & ss & ".djhtm", False
- .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
- .send
- strText = BinToStr(.responseBody, "BIG5") '要注意網頁編碼
- End With
- With CreateObject("htmlfile")
- .Write strText
- Set xTable = .all.tags("table")(2)
- With 工作表2
- .Cells.Clear
- For i = 0 To xTable.Rows.Length - 1
- For j = 0 To xTable.Rows(i).Cells.Length - 1
- .Cells(i + 1, j + 1) = xTable.Rows(i).Cells(j).innertext
- Next
- Next
- End With
- End With
- End Sub
- Private Sub GetClosePrice(ByVal ss As String) ' 取基本資料
- Dim strText As String
- Dim i As Integer, j As Integer, xTable As Object
- With CreateObject("msxml2.xmlhttp")
- .Open "GET", "http://pscnetinvest.moneydj.com.tw/z/zc/zca/zca_" & ss & ".djhtm", False
- .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
- .send
- strText = BinToStr(.responseBody, "BIG5") '要注意網頁編碼
- End With
- With CreateObject("htmlfile")
- .Write strText
- Set xTable = .all.tags("table")(2)
- With 工作表3
- .Cells.Clear
- For i = 0 To xTable.Rows.Length - 1
- For j = 0 To xTable.Rows(i).Cells.Length - 1
- .Cells(i + 1, j + 1) = xTable.Rows(i).Cells(j).innertext
- Next
- Next
- End With
- End With
- End Sub
- Private Sub GetIncome(ByVal ss As String) '取損益表(年表)網頁
- Dim strText As String
- Dim i As Integer, j As Integer, xTable As Object
- With CreateObject("msxml2.xmlhttp")
- .Open "GET", "http://kgieworld.moneydj.com/z/zc/zcq/zcqa/zcqa_" & ss & ".djhtm", False
- .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
- .send
- strText = BinToStr(.responseBody, "BIG5") '要注意網頁編碼
- End With
- With CreateObject("htmlfile")
- .Write strText
- Set xTable = .all.tags("table")(2)
- With 工作表4
- .Cells.Clear
- For i = 0 To xTable.Rows.Length - 1
- For j = 0 To xTable.Rows(i).Cells.Length - 1
- .Cells(i + 1, j + 1) = xTable.Rows(i).Cells(j).innertext
- Next
- Next
- End With
- End With
- End Sub
- Private Sub GetBalance(ByVal ss As String) '取資產負債表(年表)網頁
- Dim strText As String
- Dim i As Integer, j As Integer, xTable As Object
- With CreateObject("msxml2.xmlhttp")
- .Open "GET", "http://kgieworld.moneydj.com/z/zc/zcp/zcpb/zcpb_" & ss & ".djhtm", False
- .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
- .send
- strText = BinToStr(.responseBody, "BIG5") '要注意網頁編碼
- End With
- With CreateObject("htmlfile")
- .Write strText
- Set xTable = .all.tags("table")(2)
- With 工作表5
- .Cells.Clear
- For i = 0 To xTable.Rows.Length - 1
- For j = 0 To xTable.Rows(i).Cells.Length - 1
- .Cells(i + 1, j + 1) = xTable.Rows(i).Cells(j).innertext
- Next
- Next
- End With
- End With
- End Sub
- Private Sub GetShareholding(ByVal ss As String) '取董監持股網頁
- Dim strText As String
- Dim i As Integer, j As Integer, xTable As Object
- With CreateObject("msxml2.xmlhttp")
- .Open "GET", "http://pscnetinvest.moneydj.com.tw/z/zc/zcj/zcj_" & ss & ".djhtm", False
- .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
- .send
- strText = BinToStr(.responseBody, "BIG5") '要注意網頁編碼
- End With
- With CreateObject("htmlfile")
- .Write strText
- Set xTable = .all.tags("table")(3)
- With 工作表6
- .Cells.Clear
- For i = 0 To xTable.Rows.Length - 1
- For j = 0 To xTable.Rows(i).Cells.Length - 1
- .Cells(i + 1, j + 1) = xTable.Rows(i).Cells(j).innertext
- Next
- Next
- End With
- End With
- End Sub
- Function BinToStr(arrBin, strChrs)
- With CreateObject("ADODB.Stream")
- .Type = 2
- .Open
- .Writetext arrBin
- .Position = 0
- .Charset = strChrs
- BinToStr = .ReadText
- .Close
- End With
- End Function
複製代碼 |
|