2010-11-08 自動填入值並按 查詢 按鈕(webbrowser) (VB) 38415 0 VB 自動填入值並按 查詢 按鈕(webbrowser) (VB) Option Explicit Dim wb As Integer Dim WithEvents Web_V1 As SHDocVwCtl.WebBrowser_V1 Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private hdoc As MSHTML.HTMLDocument ' 引用項目 Microsoft HTML Object Library Dim times As Integer Private Sub Form_Load() Set Web_V1 = WebBrowser1.Object '讓查詢網頁在webbrowser顯示 不另開視窗 WebBrowser1.navigate "http://mops.twse.com.tw/server-java/t13sa150_otc?&step=1" End Sub Private Sub webbrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant) Dim vdoc, vTag, j Set hdoc = WebBrowser1.document If (pDisp Is WebBrowser1.Object) Then If times < 1 Then '只有啟動那次會查詢 wb = 1 Set vdoc = WebBrowser1.document vdoc.All("years").Value = "2009" '填西元年 vdoc.All("months").Value = "07" '月份 兩碼 vdoc.All("days").Value = "01" '日期 兩碼 For j = 0 To vdoc.All.length - 1 '檢測所有標籤 Debug.Print UCase(vdoc.All(j).tagName) & "-" & j If UCase(vdoc.All(j).tagName) = "INPUT" Then vdoc.All.Item(j).Click '點擊按鈕 Next j times = 1 ' set times=1 End If End If End Sub Private Sub Web_V1_NewWindow(ByVal URL As String, _ ByVal Flags As Long, _ ByVal TargetFrameName As String, _ PostData As Variant, _ ByVal Headers As String, _ Processed As Boolean) Processed = True WebBrowser1.navigate URL End Sub 如有錯誤 歡迎指正 回首頁