gpt4 book ai didi

VBA 将文件夹中的 csv 文件转换为 xlsx 文件

转载 作者:行者123 更新时间:2023-12-04 19:47:40 25 4
gpt4 key购买 nike

我有这个代码。

此代码转换为 xlsm 文件。

我想转换成 xlsx 文件。

如何?

我尝试通过改变

wBook.SaveAs XlsFolder & Replace(fname, ".csv", ""), ThisWorkbook.FileFormatTO
wBook.SaveAs XlsFolder & Replace(fname, ".csv", ".xlsx")

它没有用。

Private Sub CommandButton2_Click()
Dim CSVfolder As String
Dim XlsFolder As String
Dim fname As String
Dim wBook As Workbook

CSVfolder = "C:\csv\"
XlsFolder = "C:\Charts\"

fname = Dir(CSVfolder & "*.csv")

Do While fname <> ""
Set wBook = Workbooks.Open(CSVfolder & fname, Format:=6, Delimiter:=",")
wBook.SaveAs XlsFolder & Replace(fname, ".csv", ""), ThisWorkbook.FileFormat
wBook.Close False
fname = Dir
Loop
End Sub

最佳答案

使用宏重新编码器,xlsx 工作簿的文件格式为 FileFormat:=xlOpenXMLWorkbook

所以这是你的代码:

Private Sub CommandButton2_Click()
Dim CSVfolder As String, _
XlsFolder As String, _
fname As String, _
wBook As Workbook

CSVfolder = "C:\csv\"
XlsFolder = "C:\Charts\"

fname = Dir(CSVfolder & "*.csv")

Do While fname <> ""
Set wBook = Workbooks.Open(CSVfolder & fname, Format:=6, Delimiter:=",")
wBook.SaveAs XlsFolder & Replace(fname, ".csv", ""), xlOpenXMLWorkbook
wBook.Close False
fname = Dir
Loop
End Sub

关于VBA 将文件夹中的 csv 文件转换为 xlsx 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30757897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com