ExcelTip.Net留存知识帖 ---【注:附件之前被网盘供应商清空后,现已修复-现已修复-现已修复为本地下载!】
现在位置:首页 > 我的酷贴 > Excel VBA > 定时查询伦敦黄金数据的小程序

定时查询伦敦黄金数据的小程序

作者:绿色风 分类: 时间:2022-08-18 浏览:64
楼主
xmyjk
  1. Option Explicit
  2. Dim Interval As Date
  3. Sub autoref()
  4.     Dim tmp() As String, i As Integer, arr() As String, xmlhttp As Object
  5.       
  6.     [h1:m1] = Split("货币,最新价,最高价,最低价,升跌,更新时间", ",")
  7.     [m2] = Format(Date, "yyyy年mm月dd日") & Format(Time, "Long Time")
  8.    
  9.     On Error Resume Next
  10.     Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
  11.     With xmlhttp
  12.         .Open "get", "http://www.hx9999.com/api/gold.php?" & Rnd, False
  13.         .send
  14.         tmp() = Filter(Split(Replace(Replace(Replace(.responsetext, "align=""center"" style=""color:Red"">", ""), "align=""center"" style=""color:Green"">", ""), "align=""center"" style=""color:Black"">", ""), "align=""center"""), "</td>")
  15.     End With
  16.     ReDim arr(UBound(tmp) \ 5, 4)
  17.     For i = 0 To UBound(tmp)
  18.       arr(i \ 5, i Mod 5) = Split(Split(tmp(i), "</td>")(0), ">")(1)
  19.     Next
  20.     [h1].Resize(UBound(arr, 1) + 1, UBound(arr, 2) + 1) = arr
  21.    
  22.     [h:m].Columns.AutoFit
  23.     Erase tmp
  24.     Erase arr
  25.     Set xmlhttp = Nothing
  26.    
  27.     Range("A2:F2").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
  28.     Range("H2:M2").Copy Destination:=Range("A2")
  29.    
  30. Interval = Now + TimeSerial(0, 0, 10) '10秒钟刷新一次
  31. Application.OnTime Interval, "autoref"

  32. End Sub

  33. Sub autostop()
  34.   Application.OnTime Interval, "autoref", , False
  35. End Sub

  36. Sub ref()
  37.     Dim tmp() As String, i As Integer, arr() As String, xmlhttp As Object
  38.       
  39.     [h1:m1] = Split("货币,最新价,最高价,最低价,升跌,更新时间", ",")
  40.     [m2] = Format(Date, "yyyy年mm月dd日") & Format(Time, "Long Time")
  41.    
  42.     On Error Resume Next
  43.     Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
  44.     With xmlhttp
  45.         .Open "get", "http://www.hx9999.com/api/gold.php?" & Rnd, False
  46.         .send
  47.         tmp() = Filter(Split(Replace(Replace(Replace(.responsetext, "align=""center"" style=""color:Red"">", ""), "align=""center"" style=""color:Green"">", ""), "align=""center"" style=""color:Black"">", ""), "align=""center"""), "</td>")
  48.     End With
  49.     ReDim arr(UBound(tmp) \ 5, 4)
  50.     For i = 0 To UBound(tmp)
  51.       arr(i \ 5, i Mod 5) = Split(Split(tmp(i), "</td>")(0), ">")(1)
  52.     Next
  53.     [h1].Resize(UBound(arr, 1) + 1, UBound(arr, 2) + 1) = arr
  54.    
  55.     [h:m].Columns.AutoFit
  56.     Erase tmp
  57.     Erase arr
  58.     Set xmlhttp = Nothing
  59.    
  60.     Range("A2:F2").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
  61.     Range("H2:M2").Copy Destination:=Range("A2")
  62.    
  63.     MsgBox "手动刷新成功!"

  64. End Sub

现货黄金new.rar
2楼
liumporite
8错dddddddddddddddddd

免责声明

有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素, 经与ExcelTip.Net站长Apolloh商议并征得其同意, 现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示, 供有需要的人士查询使用,也慰缅曾经的论坛时代。 所示各个帖子的原作者如对版权有异议, 可与本人沟通提出,或于本站点留言,我们会尽快处理。 在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一

评论列表
sitemap