Excel精英培训网

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

[已解决]帮忙看下这个导入数据代码,为什么会出错

[复制链接]
发表于 2012-3-16 15:32 | 显示全部楼层 |阅读模式
我写了个代码将.csv 文件中的数据导入到excel 中,这个csv文件在当前文件夹中,但是运行时这个代码会报错,请教这是为什么?

sub test()
Sheets("data").Columns("A:AO").ClearContents
With Sheets("data").QueryTables.Add(Connection:= _
        "TEXT;ThisWorkbook.Path &\Rawdata.csv", Destination:=Sheets("data").Range("$A$1"))
        .TextFileCommaDelimiter = True
        .Refresh BackgroundQuery:=False
    End With
end sub
最佳答案
2012-3-17 01:59
'See below minor changes (in red):

Sub test()
Sheets("data").Columns("A:AO").ClearContents
With Sheets("data").QueryTables.Add(Connection:= _
        "TEXT;" & ThisWorkbook.Path & "\Rawdata.csv", Destination:=Sheets("data").Range("$A$1"))
        .TextFileCommaDelimiter = True
        .Refresh BackgroundQuery:=False
    End With
End sub



excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2012-3-17 01:59 | 显示全部楼层    本楼为最佳答案   
'See below minor changes (in red):

Sub test()
Sheets("data").Columns("A:AO").ClearContents
With Sheets("data").QueryTables.Add(Connection:= _
        "TEXT;" & ThisWorkbook.Path & "\Rawdata.csv", Destination:=Sheets("data").Range("$A$1"))
        .TextFileCommaDelimiter = True
        .Refresh BackgroundQuery:=False
    End With
End sub



回复

使用道具 举报

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

本版积分规则

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

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

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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