有没有办法将数据从.csv导入到活动Excel表? [英] Is there a way to import data from .csv to active excel sheet?

查看:176
本文介绍了有没有办法将数据从.csv导入到活动Excel表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为相同的csv文件,名为SO2PO.csv。它有一个数据,我导入到一个名为PO Data的excel表中,名为Open Order的工作簿。我需要找到一种从SO2PO.csv导入所有数据到打开Order.xlsm表PO Data的方法。



我知道这是可能的,但是如何?有人可以指向正确的方向吗?



还是有一种方法可以导入任何放在特定文件夹中的.csv文件? / p>

解决方案

添加此代码在PO数据表中创建一个QueryTable到您的数据源



创建QueryTable后,您可以右键单击刷新数据(或打开刷新)

  Sub CSV_Import()
Dim ws As Worksheet,strFile As String

设置ws = ActiveWorkbook.Sheets(PO Data)'设置为当前工作表名称

strFile = Application.GetOpenFilename(Text Files(* .csv),*。csv,请选择文本文件...)

使用ws.QueryTables.Add(Connection:= TEXT;& strFile,Destination:= ws.Range(A1))
.TextFileParseType = xlDelimited
.TextFileCommaDelimiter = True
.Refresh
End with
End Sub


I have a csv file always named the same, called SO2PO.csv. It has data that I import into an excell sheet called PO Data, in a workbook called Open Order. I need to find a way to import all the data from SO2PO.csv to Open Order.xlsm sheet PO Data.

I know it's possible, but how? Can someone point me in the right direction?

Or is there a way to make it so that I can import any .csv file that in placed into a specific folder?

解决方案

Add this code to create a QueryTable in the PO Data sheet to your data source

Once you have created the QueryTable you can then just right click Refresh the data (or refresh on open)

Sub CSV_Import()
Dim ws As Worksheet, strFile As String

Set ws = ActiveWorkbook.Sheets("PO Data") 'set to current worksheet name

strFile = Application.GetOpenFilename("Text Files (*.csv),*.csv", , "Please select text file...")

With ws.QueryTables.Add(Connection:="TEXT;" & strFile, Destination:=ws.Range("A1"))
     .TextFileParseType = xlDelimited
     .TextFileCommaDelimiter = True
     .Refresh
End With
End Sub

这篇关于有没有办法将数据从.csv导入到活动Excel表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆