- 帖子
- 142
- 主題
- 18
- 精華
- 0
- 積分
- 160
- 點名
- 264
- 作業系統
- win10 64位元
- 軟體版本
- office2003
- 閱讀權限
- 20
- 性別
- 男
- 來自
- 臺灣 高雄市
- 註冊時間
- 2015-7-18
- 最後登錄
- 2026-10-1
         
|
[發問] 請問能否將2個VBA巨集合併成1個VBA巨集
本帖最後由 lcctno 於 2015-7-23 21:06 編輯
我是初學者 網路上找了數天 但一直找不到方法 請高手們拉我一把 謝謝
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 |
|