VBA 根据股票代码查询价格
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VBA 根据股票代码查询价格相关的知识,希望对你有一定的参考价值。
未实现定时刷新 Sub 抓取股票价格() On Error Resume Next Set regx = CreateObject("vbscript.regexp") ‘ regx.Global = True regx.Pattern = "\[""(.*)"",""(.*)"",(\d+),(.*),(.*),(\d{8}).*\]" ‘ arr_stock = Range(Cells(2, 1), Cells(Cells(Rows.Count, 1).End(xlUp).Row, 1)) ‘股票代码数组 string_stock = Join(Application.Transpose(arr_stock), ",") ‘股票代码数组分成字符串 https = "http://q.jrjimg.cn/?q=cn|s&i=" https = https & string_stock & "&c=code,name,np,pl,time,stp&o=pl,d&n=realHqxny_concept_9000&_=1507340273905" Set ie = CreateObject("internetexplorer.application") ie.navigate https Do Until ie.readystate = 4 DoEvents Loop With ie.document string_body = .body.innerText ‘返回的代码 Set mh = regx.Execute(string_body) ‘应用正则 For Each m In mh i = i + 1 Cells(i + 1, 2) = m.submatches(1) ‘公司名称 Cells(i + 1, 3) = m.submatches(3) ‘价格 Cells(i + 1, 4) = m.submatches(4) ‘涨跌幅 Cells(i + 1, 5) = m.submatches(5) ‘日期 Next ie.Quit End With Set ie = Nothing Set regx = Nothing End Sub
以上是关于VBA 根据股票代码查询价格的主要内容,如果未能解决你的问题,请参考以下文章