VBA巨集.1
Sub 即時淨值()
Dim E As Object, myItems As Object, myitem
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate "http://www.yuantaetfs.com/#/RtNav/Index"
Do While .Busy Or .readyState <> 4: DoEvents: Loop
'Application.Wait Now + #12:00:01 AM# '有錯在開啟
Set myItems = .Document.getElementsByTagName("button")
For Each myitem In myItems
If myitem.Name = "Agree" Then
myitem.Click '按下送出查詢按鈕
End If
Next
Application.Wait Now + #12:00:01 AM#
Set E = .Document.getElementsByTagName("TABLE")(21)
.Document.body.innerHTML = E.outerHTML
.ExecWB 17, 2 ' Select All
.ExecWB 12, 2 ' Copy selection
With ActiveSheet
'.Cells.Clear
.[A1].Select
.PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
End With
.Quit '關閉網頁
End With
Range("L1:Q19").Select
Selection.ClearContents
Range("D16:D17").Select
With Selection.Interior
.ColorIndex = 35
.Pattern = xlSolid
End With
End Sub
VBA巨集 2
Sub 國內指數()
Dim E As Object, myItems As Object, myitem
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate "http://www.yuantaetfs.com/#/Home/Index"
Do While .Busy Or .readyState <> 4: DoEvents: Loop
'Application.Wait Now + #12:00:01 AM# '有錯在開啟
Set myItems = .Document.getElementsByTagName("button")
For Each myitem In myItems
If myitem.Name = "Agree" Then
myitem.Click '按下送出查詢按鈕
End If
Next
Application.Wait Now + #12:00:01 AM#
Set E = .Document.getElementsByTagName("TABLE")(22)
.Document.body.innerHTML = E.outerHTML
.ExecWB 17, 2 ' Select All
.ExecWB 12, 2 ' Copy selection
With ActiveSheet
'.Cells.Clear
.[A27].Select
.PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
End With
.Quit '關閉網頁
End With
Range("A39:E39").Select
Selection.ClearContents
Range("C27:C28").Select
With Selection.Interior
.ColorIndex = 35
.Pattern = xlSolid
End With
End Sub作者: Min 時間: 2015-7-25 00:22
這樣嗎? 呵呵呵~ 不是很懂您想要的...
sub run_all()
call 即時淨值()
call 國內指數()
end sub作者: lcctno 時間: 2015-7-25 06:57
PA = Array("{""fundId"":""[\d]+"",""etfId"":""(.+?)"",""name"":""(.+?)"",""ename"":""[^""]*"",""yestNav"":(.+?),""nav"":(.+?),""navFluct"":(.+?),""yestPrice"":(.+?),""price"":(.+?),""priceFluct"":(.+?),""yestIndex"":(.+?),""index"":(.+?),""indexFluct"":(.+?),""updateTime"":""(.+?)"",""AllowMark"":""(.+?)"",""RedemMark"":""(.+?)"",""BussMark"":""(.+?)"",[^}]+}", _
回復 49#no3-taco
以下內容可能有誤 因為還是出現訊息 "400"
Sub test()
Dim E As Object, AR(), i As Integer
AR = Array("http://www.yuantaetfs.com/#/RtNav/Index", "http://www.yuantaetfs.com/#/Home/Index")
'Ar = Array(網址:即時淨值,網址:國內指數) 網址置入陣列
ActiveSheet.UsedRange.Clear
For i = 0 To 1
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate AR(i)
Do While .Busy Or .readyState <> 4: DoEvents: Loop
If i = 0 Then '國內指數:不需按下同意鍵
Do
Set E = .Document.getElementByid("Agree")
Loop Until Not E Is Nothing
E.Click
End If
.Visible = False
Application.VBE.MainWindow.Visible = True
Application.VBE.Windows("即時運算").Visible = True
Stop '之後按下F5
Do
Do
Set E = .Document.getElementsByTagName("TABLE")(21 + i)
'即時淨值 第21個 "TABLE" ,'國內指數 第22個 "TABLE"
Debug.Print i, "e Is Nothing ->", E Is Nothing
Loop Until Not E Is Nothing
Debug.Print i, "e Is Nothing ->", E Is Nothing, "e.all.Length", E.all.Length
Loop Until E.all.Length >= IIf(i = 0, 415, 135) '
Stop '之後按下F5
Application.VBE.Windows("即時運算").Visible = False
Application.VBE.MainWindow.Visible = False
.Document.body.innerHTML = E.outerHTML
.ExecWB 17, 2 ' Select All
.ExecWB 12, 2 ' Copy selection
With ActiveSheet
.Range("A" & IIf(i = 0, 1, 27)).Select
.PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
With .Range(IIf(i = 0, "D16:D17", "C27:C28")).Interior
.ColorIndex = 35
.Pattern = xlSolid
End With
End With
.Quit '關閉網頁
End With
Next
End Sub