- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
17#
發表於 2016-6-12 07:51
| 只看該作者
本帖最後由 GBKEE 於 2016-6-12 15:02 編輯
回復 16# c_c_lai
url 裡為何我一直抓不到正確的 selectType 對應值?
網頁的建置我沒入門,所以我也在摸索中
.getElementsByName: getElements 複數-> 物件的集合
.getElementsBytagName: getElements 複數-> 物件的集合
.ALL.tags: tags 複數-> 物件的集合
.getElementById : getElement 單數 ->單一的物件- Set xTable = oHtmldoc.ALL.tags("TABLE")
- Stop
- '看看區域變數視窗 xTable 的內容
- Set xTable = oHtmldoc.ALL.tags("TABLE")(0)
- Stop
- '再次看看區域變數視窗 xTable 的內容
- MsgBox xTable.INNERTEXT
複製代碼 附檔中有許多相同的程式碼.,,,,,,,,,,,- TVal = Array("MS", "", "0049", "0099P", "019919T", "0999", "0999P", "01", "02", "03", _
- "04", "05", "06", "07", "21", "22", "08", "09", "10", _
- "11", "12", "13", "24", "25", "26", "27", "28", "29", _
- "30", "31", "14", "15", "16", "17", "18", "23", "9299", "19", "20", "CB")
- '**************************
- If .ComboBox1.Value = "Select Name" Then
- MsgBox ("您尚未選擇「產業類別」,請於" & vbCrLf & "確認後再次點選『開啟網頁』," & vbCrLf & "謝謝您!")
- Exit Sub
- End If
- For cts = 0 To UBound(lst)
- If lst(cts) = .[D1] Then select2 = TVal(cts): Exit For
- Next cts
複製代碼 可以整合一下- Option Explicit
- Const MyUrl = "http://www.twse.com.tw/ch/trading/exchange/MI_MARGN/MI_MARGN.php"
- Private Sub Workbook_Open()
- Dim oHtmldoc, op, cts
- Set oHtmldoc = CreateObject("htmlfile")
- With CreateObject("msxml2.xmlhttp")
- .Open "Get", MyUrl, False
- .Send
- Do While .Status <> 200 Or .readyState <> 4: DoEvents: Loop
- oHtmldoc.write .responseText
- End With
- Set op = oHtmldoc.all.tags("select")("selectType")
- With Sheets("總表").ComboBox1
- .Clear
- For cts = 0 To op.Length - 1
- .AddItem '清單方塊或下拉式清單方塊中加入一個項目
- .List(.ListCount - 1, 0) = op(cts).Text ' 第1欄,最多9欄
- .List(.ListCount - 1, 1) = op(cts).Value ' 第2欄,最多9欄
- Next
- .Value = "Select Name" '.List(0) '0: 信用交易統計, 1:全部,2: 封閉式基金......
- End With
- End Sub
複製代碼- Private Function Select_Name() As Integer
- With Sheets("總表").ComboBox1
- If .ListIndex = -1 Then MsgBox ("您尚未選擇「產業類別」,請於" & vbCrLf & "確認後再次點選『開啟網頁』," & vbCrLf & "謝謝您!")
- Select_Name = .ListIndex
- End With
- End Function
複製代碼- Sub 融資融券2()
- Dim qdate As String, select2 As String
- 'Dim TVal(), cts As Integer
- If Select_Name = -1 Then
- Exit Sub
- Else
- With Sheets("總表")
- qdate = Format(.[B1], "EE/MM/DD")
- With .ComboBox1
- select2 = .List(.ListIndex, 1)
- End With
- End With
- End If
- With Sheets("融資_融券")
- .Select
- .Cells.Clear
- End With
複製代碼 |
|