' stock_list = "tse_1101.tw|tse_2317.tw|tse_2448.tw|tse_3037.tw|otc_1264.tw"
stock_list = ""
For K = 12 To 39 Step 4
str33 = CStr(Cells(1, K))
If Len(str33) = 4 Then
If stock_list = "" Then
stock_list = "tse_" & str33 & ".tw"
Else
stock_list = stock_list & "|tse_" & str33 & ".tw"
End If
End If
Next K
str31 = "https://mis.twse.com.tw/stock/api/getStockInfo.jsp?json=1&delay=0&ex_ch=" & stock_list
Set IE = CreateObject("internetexplorer.application") ' 使用此方式可以免除 "設定引用項目"
With IE
.Visible = False ' True 為開啟 ie, False 為不開啟 ie
.Navigate str31
Do While .ReadyState <> 4 ' 等待網頁開啟
DoEvents
Loop
.ExecWB 17, 2 ' Select All
.ExecWB 12, 2 ' Copy selection
Range("A21").Select
ActiveSheet.PasteSpecial Format:="HTML", link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
End With
IE.Quit
FileD = ActiveWorkbook.Path & "\下載\Temp.d"
str22 = Trim(CStr(Cells(21, 1)))
Range("A21").ClearContents
h22 = Len(str22)
If h22 > 10 Then
Open FileD For Output As #1
h1 = 1
While h1 < h22
h2 = InStr(h1, str22, "}")
LW = Mid$(str22, h1, h2 - h1 + 1)
If Mid$(LW, 1, 1) = "{" Then Print #1, LW
h1 = h2 + 2
Wend
Close #1