|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
renahu 发表于 2014-11-16 16:01
看看我的最新版,呵呵,看看是不是更精细了?请高手帮我优化一下,另外看看还有什么可以改进的?这个版本 ...
在ThisWorkbook中增加如下代码(红色字体部分),以在打开工作薄时获取图书分类数据。
Private Sub Workbook_Open()
Call 登陆
login = True
获取分类数据
Call 一级菜单初始化
End Sub
Sub 获取分类数据()
'On Error Resume Next
Dim strText As String, i%, j%, r As Long, arr, brr, sh
Set sh = Sheets("分类数据")
sh.UsedRange.Offset(1).Clear
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "http://www.apabi.com/cdyxy/?pid=dlib.index", False
.send
strText = Split(Split(.responsetext, "<h2>书苑常用分类</h2>")(1), "<h2>新书推荐</h2>")(0)
'Debug.Print strText
arr = Split(strText, "<h3")
For i = 1 To UBound(arr)
r = r + 1
sh.Cells(r + 1, 1) = Split(Split(arr(i), ">")(2), "<")(0)
sh.Cells(r + 1, 2) = "全部"
sh.Cells(r + 1, 3) = Split(Split(arr(i), "cc=")(1), "&")(0)
brr = Split(Split(arr(i), "<ul>")(1), "</a></li>")
For j = 0 To UBound(brr) - 1
r = r + 1
sh.Cells(r + 1, 1) = Split(Split(arr(i), ">")(2), "<")(0)
sh.Cells(r + 1, 2) = Split(brr(j), ">")(2)
sh.Cells(r + 1, 3) = Split(Split(brr(j), "cc=")(1), "&")(0)
Next j
Next i
End With
End Sub |
|