ExcelTip.Net留存知识帖 ---【注:附件之前被网盘供应商清空后,现已修复-现已修复-现已修复为本地下载!】
现在位置:首页 > 我的酷贴 > Excel VBA > 如何运用VBA获取网页上各理财产品的对比情况

如何运用VBA获取网页上各理财产品的对比情况

作者:绿色风 分类: 时间:2022-08-18 浏览:117
楼主
xmyjk
Q:如何运用VBA获取网页上各理财产品的对比情况?网址:

A:
  1. Option Explicit

  2. Private Declare Sub DeleteUrlCacheEntry Lib "wininet.dll" (ByVal lpszUrlName As String)


  3. Sub CommandButton1_Click()

  4. Dim Xmlhttp As Object, Adodb As Object

  5. Sheets(1).Image1.Picture = LoadPicture("")
  6. If Dir(ThisWorkbook.Path & "\" & "1" & ".jpg") <> "" Then Kill (ThisWorkbook.Path & "\" & "1" & ".jpg")

  7. Dim Strlcx As String, Strbjx As String, Strqijian As String
  8. Dim Lcx As String, Bjx As String, Qijian As String

  9. Strlcx = Trim(Range("c25").Value)
  10. Strbjx = Trim(Range("f25").Value)
  11. Strqijian = Trim(Range("c27").Value)

  12. Select Case Strlcx
  13.    Case "e理财投连B款"
  14.      Lcx = "118201"
  15.    Case "积极成长型账户"
  16.      Lcx = "506003"
  17.    Case "稳健收益型账户"
  18.      Lcx = "506001"
  19. End Select

  20. Select Case Strbjx
  21.    Case "上证指数"
  22.      Bjx = "SZ"
  23.    Case "上证180"
  24.      Bjx = "ZS000010"
  25.    Case "上证50"
  26.      Bjx = "ZS000016"
  27.    Case "上证基金指数"
  28.      Bjx = "ZS000011"
  29.    Case "国债指数"
  30.      Bjx = "ZS000012"
  31.    Case "沪深300"
  32.      Bjx = "ZS000300"
  33.    Case "中债指数"
  34.      Bjx = "ZZ"
  35.    Case "中小板指"
  36.      Bjx = "ZS399005"
  37.    Case "深证成指"
  38.      Bjx = "ZS399001"
  39.    Case "深证综指"
  40.      Bjx = "ZS399106"
  41.    Case "深证基金指数"
  42.      Bjx = "ZS399305"
  43.    Case "银华核心价值优选基金"
  44.      Bjx = "519001"
  45.    Case "华夏大盘精选基金"
  46.      Bjx = "000011"
  47.    Case "华夏复兴基金"
  48.      Bjx = "000031"
  49.    Case "华夏成长基金"
  50.      Bjx = "000001"
  51.    Case "交银成长基金"
  52.      Bjx = "519692"
  53.    Case "银华领先策略基金"
  54.      Bjx = "180013"
  55. End Select

  56. Select Case Strqijian
  57.    Case "10天"
  58.      Qijian = "10"
  59.    Case "30天"
  60.      Qijian = "30"
  61.    Case "90天"
  62.      Qijian = "90"
  63.    Case "180天"
  64.      Qijian = "180"
  65.     Case "1年"
  66.      Qijian = "1"
  67.     Case "3年"
  68.      Qijian = "3"
  69. End Select

  70. Dim Url As String
  71. Url = "http://mall.taikang.com/elicai/image.jsp?accountid=" & Lcx & "&fundcode=" & Bjx & "&period=" & Qijian

  72. Set Xmlhttp = CreateObject("Microsoft.XMLHTTP")
  73. Xmlhttp.Open "get", Url, False
  74. Xmlhttp.setRequestHeader "Content-Type", "text/html"
  75. Xmlhttp.Send ""
  76. Do Until Xmlhttp.ReadyState = 4
  77. DoEvents
  78. Loop

  79. Set Xmlhttp = Nothing

  80. Set Xmlhttp = CreateObject("Microsoft.XMLHTTP")
  81. Xmlhttp.Open "get", "http://mall.taikang.com/elicai/imageServlet", False
  82. Xmlhttp.setRequestHeader "Content-Type", "image/jpeg"
  83. Xmlhttp.Send ""
  84. Do Until Xmlhttp.ReadyState = 4
  85. DoEvents
  86. Loop

  87. If Xmlhttp.Status = 200 Then

  88. Set Adodb = CreateObject("ADODB.Stream")
  89.    With Adodb
  90.             .Type = 1
  91.             .Open
  92.             .write Xmlhttp.Responsebody
  93.             .savetofile ThisWorkbook.Path & "\" & "1" & ".jpg", 2   '另存图片
  94.             .Close
  95. End With
  96. Sheets(1).Image1.Picture = LoadPicture(ThisWorkbook.Path & "\" & "1" & ".jpg")

  97. Else
  98.   reportErr (Xmlhttp.Status)
  99. End If

  100. Set Xmlhttp = Nothing
  101. Set Adodb = Nothing


  102. DeleteUrlCacheEntry "http://mall.taikang.com/elicai/imageServlet"

  103. If Dir(ThisWorkbook.Path & "\" & "1" & ".jpg") <> "" Then Kill (ThisWorkbook.Path & "\" & "1" & ".jpg")

  104. MsgBox "查询并加载图片成功!"


  105. End Sub

  106. Sub reportErr(lStatus As Integer)
  107.         Select Case lStatus
  108.             Case 400
  109.                 MsgBox "Bad Request", vbCritical, "连接错误"
  110.             Case 401
  111.                 MsgBox "Unauthorized", vbCritical, "连接错误"
  112.             Case 402
  113.                 MsgBox "Payment Required", vbCritical, "连接错误"
  114.             Case 403
  115.                 MsgBox "Forbidden", vbCritical, "连接错误"
  116.             Case 404
  117.                 MsgBox "Not Found", vbCritical, "连接错误"
  118.             Case 407
  119.               MsgBox "Proxy Authentication Required", vbCritical, "连接错误"
  120.             Case 408
  121.                 MsgBox "Request Timeout", vbCritical, "连接错误"
  122.             Case 503
  123.                 MsgBox "Service Unavailable", vbCritical, "连接错误"
  124.             Case Else
  125.               MsgBox "Can not reach by other reason", vbCritical, "连接错误"
  126.         End Select

  127. End Sub

账户对比.rar
2楼
bishunbiao
师傅,推荐一款理财产品吧。

免责声明

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

评论列表
sitemap