Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2914|回复: 3

[已解决]导出分页数据到excel中文全是乱码

[复制链接]
发表于 2017-2-7 21:06 | 显示全部楼层 |阅读模式
Option Explicit
Sub test()
    Dim HTML, tb, i&, j&, x&, n&, s$
    [a2:d9999] = ""
    Set HTML = CreateObject("htmlfile")
    With CreateObject("msxml2.xmlhttp")
        For x = 0 To 22
            .Open "get", "http:www、csyyhb.cn/plist.asp?lx=small&anid=18&nid=31&Page=" & 30 * x, False
            .Send
            Application.Wait (Now + TimeValue("00:00:02"))
            HTML.body.innerhtml = .responsetext
            Set tb = HTML.ALL.tags("table")(0).Rows
            For i = 1 To tb.Length - 1
                n = n + 1
                For j = 0 To tb(i).Cells.Length - 1
                    Cells(n + 1, j + 1) = tb(i).Cells(j).innertext
                Next
            Next
        Next
    End With
    MsgBox "获取完毕!"
End Sub


麻烦大神帮我看看好吗,我实在不知道该怎么办了。哪里出了问题。编码我也看了,是一样的。中文显示的是带框框的问号~



最佳答案
2017-2-8 09:20
  HTML.body.innerhtml = .responsetext

改成

HTML.body.innerhtml = StrConv(.responseBody, vbUnicode)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
 楼主| 发表于 2017-2-7 22:47 | 显示全部楼层
Sub GSF()

    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http:嘿哟嘿哟//www嘿哟csyyhb.cn/plist.asp?lx=small&anid=18&nid=19&Page=1" _
        , Destination:=Range("B1"))
        .PreserveFormatting = True
        .AdjustColumnWidth = True
        .WebTables = "1"
        .Refresh BackgroundQuery:=False
    End With
    Columns("A:A").Select
    Selection.ClearContents
    Range("A1").Select
End Sub

我用了这个,但是它不会自动翻页……请问有人能帮帮我吗 感谢~
回复

使用道具 举报

发表于 2017-2-8 09:20 | 显示全部楼层    本楼为最佳答案   
  HTML.body.innerhtml = .responsetext

改成

HTML.body.innerhtml = StrConv(.responseBody, vbUnicode)

评分

参与人数 1 +1 收起 理由
xky70 + 1 来学习

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2017-2-12 21:44 | 显示全部楼层
雪舞子 发表于 2017-2-8 09:20
HTML.body.innerhtml = .responsetext

改成

特别感谢您~~~已经解决了~~希望能够向您多学习
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-5 17:46 , Processed in 0.274769 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表