vba 自动将数据从 CSV 导入到 excel/calc 表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7008084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 13:46:20  来源:igfitidea点击:

automatically import data from CSV to excel/calc sheet

excelexcel-vbacsvopenoffice-calcvba

提问by Meloun

I have here 12 CSV source file (just numbers separated with semicolon).

我这里有 12 个 CSV 源文件(只是用分号分隔的数字)。

I need on one action/click take this data and import it to excel/calc to 12 sheets (1 sheet for 1 csv source).

我需要一个动作/单击获取此数据并将其导入到 excel/calc 到 12 张(1 张表用于 1 个 csv 源)。

Any Idea how can I do that?

任何想法我该怎么做?

回答by JMax

you can do it with Excel vba:

你可以用 Excel vba 做到这一点:

Please let us know if you encounter some trouble building your procedure

如果您在构建过程时遇到问题,请告诉我们

回答by jonsca

By using the code in this postcombined with a loop in which you step through the filenames (which you could keep in an array of string) and vary the .Destinationwith the sheets in the workbook(you can step through them by making as many new sheets as you need in the workbook and then going from Sheets(1)through Sheets(N), where N is the number of sheets.

通过使用这篇文章中的代码结合一个循环,您可以在其中逐步执行文件名(您可以将其保存在一个字符串数组中)并随着.Destination工作簿中的工作表改变它们(您可以通过制作尽可能多的新工作表来逐步执行它们当您在工作簿需要,然后从去Sheets(1)通过Sheets(N),其中N是片材的数量。