Excel精英培训网

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

[已解决]这个代码运行太慢了那位老师帮改下谢谢!

[复制链接]
发表于 2015-4-17 14:45 | 显示全部楼层 |阅读模式
表格内容少运行快,当达到15M以上运行起来太慢有时要等半个小时左右,但另外一个代码运行不会出现这种情况,应该说是这个代码有问题麻烦老师帮改下谢谢!
Sub abc()
    Range("A3:AC3500").Clear
    k3dshijihao = "http://www.17500.cn/getData/ssq.TXT"
    d3s = "WData3D_All"
    Cells(2, 1) = "开奖期号"
    Cells(2, 2) = "开奖日期"
    Cells(2, 3) = "红"
    Cells(2, 4) = "号"
    Cells(2, 5) = " "
    Cells(2, 6) = " "
    Cells(2, 7) = " "
    Cells(2, 8) = " "
    Cells(2, 9) = "蓝"
    Cells(2, 10) = "红"
    Cells(2, 11) = "号"
    Cells(2, 12) = "出"
    Cells(2, 13) = "球"
    Cells(2, 14) = "顺"
    Cells(2, 15) = "序"
    Cells(2, 16) = "投注总额"
    Cells(2, 17) = "奖池金额"
    Cells(2, 18) = "一等注数"
    Cells(2, 19) = "一等金额"
    Cells(2, 20) = "二等注数"
    Cells(2, 21) = "二等金额"
    Cells(2, 22) = "三等注数"
    Cells(2, 23) = "金额"
    Cells(2, 24) = "四等注数"
    Cells(2, 25) = "金额"
    Cells(2, 26) = "五等注数"
    Cells(2, 27) = "金额"
    Cells(2, 28) = "六等注数"
    Cells(2, 29) = "金额"
    cz = k3dshijihao: czmc = d3s
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & cz, Destination:=Range("A3"))
        .Name = czmc
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = xlWindows
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = True
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = True
        .TextFileColumnDataTypes = Array(1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
    Range("A" & (Application.Count(Range("a1:a3000")))).Select
    End
End Sub

最佳答案
2015-4-17 19:44
本帖最后由 zjdh 于 2015-4-17 19:46 编辑


Sub abc2() '简化一下
    Range("A3:AC3500").Clear
    cz = "http://www.17500.cn/getData/ssq.TXT"
    Cells(2, 1).Resize(1, 29) = Array("开奖期号", "开奖日期", "红", "号", " ", " ", " ", " ", "蓝", "红", _
      "号", "出", "球", "顺", "序", "投注总额", "奖池金额", "一等注数", "一等金额", "二等注数", "二等金额", _
      "三等注数", "金额", "四等注数", "金额", "五等注数", "金额", "六等注数", "金额")
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & cz, Destination:=Range("A3"))
        .TextFileSpaceDelimiter = True
        .TextFileColumnDataTypes = Array(1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .Refresh
    End With
    Range("A65536").End(3).Select
End Sub

速度缘由网速!!
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2015-4-17 19:34 | 显示全部楼层
代码固然不很简洁,但不是影响速度的主因;问题应该是当时网速太慢.
回复

使用道具 举报

发表于 2015-4-17 19:44 | 显示全部楼层    本楼为最佳答案   
本帖最后由 zjdh 于 2015-4-17 19:46 编辑


Sub abc2() '简化一下
    Range("A3:AC3500").Clear
    cz = "http://www.17500.cn/getData/ssq.TXT"
    Cells(2, 1).Resize(1, 29) = Array("开奖期号", "开奖日期", "红", "号", " ", " ", " ", " ", "蓝", "红", _
      "号", "出", "球", "顺", "序", "投注总额", "奖池金额", "一等注数", "一等金额", "二等注数", "二等金额", _
      "三等注数", "金额", "四等注数", "金额", "五等注数", "金额", "六等注数", "金额")
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & cz, Destination:=Range("A3"))
        .TextFileSpaceDelimiter = True
        .TextFileColumnDataTypes = Array(1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .Refresh
    End With
    Range("A65536").End(3).Select
End Sub

速度缘由网速!!

评分

参与人数 1 +1 收起 理由
柔儿梦婷 + 1 神马都是浮云

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2015-4-19 09:52 | 显示全部楼层
zjdh 发表于 2015-4-17 19:44
Sub abc2() '简化一下
    Range("A3:AC3500").Clear
    cz = "http://www.17500.cn/getData/ssq.TXT" ...

非常感谢现在快多了1分钟就完成了谢谢!
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-27 06:42 , Processed in 0.468287 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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