永发信息网

VBA如何批量抓取数据

答案:2  悬赏:10  手机版
解决时间 2021-03-20 22:10
VBA如何批量抓取数据
最佳答案
sub extractdata()
dim c3value,g3value,c4value,e4value,c5value
excelfilename = Dir("E:\3月\" & "*.xls")
Do While excelfilename <> ""
s = "E:\3月\" & excelfilename
Workbooks.Open Filename:=s
Workbooks(excelfilename).Activate
activeworkbook.sheets("进料检验报表").activate
c3value=activesheet(3,"C")
g3value=activesheet(3,"G")
c4value=activesheet(4,"C")
e4value=activesheet(4,"E")
c5value=activesheet(5,"C")
workbooks(合并到的excel).activate
activesheet.cells(1,1)="这是表头"
activesheet.cells(activesheet.usedrange.rows.count+1,1)=c3value
activesheet.cells(activesheet.usedrange.rows.count+1,2)=g3value
activesheet.cells(activesheet.usedrange.rows.count+1,3)=c4value
activesheet.cells(activesheet.usedrange.rows.count+1,4)=e4value
activesheet.cells(activesheet.usedrange.rows.count+1,5)=c5value
(excelfilename).Close savechanges:=false
excelfilename = Dir '第二次读入的时候不用写参数
Loop
end sub追问说语法错误,什么情况啊。

全部回答
Sub 按钮1_Click()
Dim url, html
n = 1
url = "http://www.zjcredit.gov.cn:8000/ListQuery.aspx"
For j = 1 To 5 '这里控制查询的页数
pd = "sectionID=02" _
& "&sortField=CreditID" _
& "&sortDirection=1" _
& "&recordTotal=3151" _
& "&pageNo=" & j _
& "&pageLength=20" _
& "&isOpen=False&isIntermediary=False" _
& "&query_AreaCode=" _
& "&query_OrganizationCode=" _
& "&query_BusinessLicense=" _
& "&query_CorporationName=" _
& "&query_LegalRepresentative=" _
& "&query_BusinessScope=" _
& "&query_PromptSymbol=D"
pd1 = "query_AreaCode=&query_OrganizationCode=&query_BusinessLicense=&query_CorporationName=&query_LegalRepresentative=&query_BusinessScope=&query_PromptSymbol=d&queryTitle=&businessLicense=&actionType=&searchType=§ionID=02&hot=&returnFunction=parent.reset_queryTitles&query2_AreaCode=0&query2_BusinessLicense=&query2_CorporationName=&query2_OrganizationCode=&query2_LegalRepresentative=&validateTextbox="
Set html = CreateObject("htmlfile")
With CreateObject("msxml2.xmlhttp.6.0")
.Open "post", url, False
.setrequestheader "Content-Type", "application/x-www-form-urlencoded"
.send (pd)
html.body.innerhtml = .responsetext
Set tr = html.all.tags("tr")
For i = 0 To tr.Length - 1
If tr(i).bgcolor = "#ffffff" Or tr(i).bgcolor = "#f3f3f3" Then
n = n + 1
Cells(n, 1) = tr(i).ChildNodes(0).innertext
Cells(n, 2) = tr(i).ChildNodes(1).innertext
End If
Next
End With
Next
End Sub
Sub 按钮2_Click()
Range("a2:b65536").ClearContents
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
一个男人喜欢一个女人会不会经常聊到性呢?
唯雪这个名字的含义
花港大道/保利城南街(路口)在哪里啊,我有事
爸爸生日应该送什么花比较好?
华夏天空签约说是签书不签人是什么意思?
古代的鼎现在什么地方还有派什么用
寻<唐璜>中男女二重唱<把你的小手给我吧>
Ipod touch第一代怎么安装从itunes store下载
我花22万从人,手里买了套107平米的房子,办
已知x+x的负一次方=5 求x+x的负二次方的值
天龙八部我老婆40多、我85级、我永恒钻戒能升
独立上市,独立是什么意思
北辰区少儿科技馆我想知道这个在什么地方
中国移动镇江大港五星电器带店加盟店在什么地
.苹果7e3085a用什么卡?
推荐资讯
求一个 全民突击下载 地址
爱原素DIY手工坊线下体验店地址有知道的么?
速腾1.6AT变速箱油,刹车油多长时间换一次
皇家浴场(环城南路)地址有知道的么?有点事想
以也开头的成语
淘手游如何联系客服
如何让老公变得心理更成熟
哪八个字让男人风雨无阻?
魔法王座元宝怎么交易
德尔惠工厂店地址有知道的么?有点事想过去
核苷酸哪个国家的最好
oppo关机健被改了关不了机怎么调回来
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?