【问题标题】:Transform a couple of xlsx to csv将几个 xlsx 转换为 csv
【发布时间】:2013-07-01 08:07:48
【问题描述】:

在我的 Windows 电脑上,我有一个包含几个 csv 文件的文件夹,但有时它们之间有一个 xlsx 文件。

稍后我想将所有 csv 文件复制到一个文件中,以便将其加载到数据库中。 但为此,我需要将 xlsx 文件也转换为 csv。我不想单独打开所有。有没有办法自动完成?我尝试在 Excel 中创建一个宏,但我不知道如何将其应用于所有 xlsx 文件。

感谢您的帮助!

【问题讨论】:

标签: excel csv vba


【解决方案1】:

尝试 FileSystemObject 方法

strPath = "C:\PATH_TO_YOUR_FOLDER"

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.DisplayAlerts = False

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder (strPath)

For Each objFile In objFolder.Files

If objFso.GetExtensionName (objFile.Path) = "xls" Then
   Set objWorkbook = objExcel.Workbooks.Open(objFile.Path)
   ' Include your code to work with the Excel object here
   objWorkbook.Close True 'Save changes
End If

Next

objExcel.Quit

这应该让你开始。

请记住,在 2003 版之后,Excel 的 Application.FileSearch 已弃用,因此FileSystemObject 方法更好

【讨论】:

    猜你喜欢
    • 2013-07-15
    • 2018-08-27
    • 1970-01-01
    • 2012-08-12
    • 2018-08-08
    • 2015-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多