我试图导入几个CSV文件在一个工作簿的文件夹中,并粘贴每个CSV文件在一个单独的工作表。我发现this线程做导入
Sub ImportCSVs()
Dim fPath As String
Dim fCSV As String
Dim wbCSV As Workbook
Dim wbMST As Workbook
Dim xFileDialog As FileDialog
Set wbMST = ThisWorkbook
Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
xFileDialog.AllowMultiSelect = False
xFileDialog.Title = "Select a folder"
If xFileDialog.Show = -1 Then
fPath = xFileDialog.SelectedItems(1)
End If
fPath = xFileDialog.SelectedItems(1) & "\"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
fCSV = Dir(fPath & "\" & "*.csv")
On Error Resume Next
Do While Len(fCSV) > 0
Set wbCSV = Workbooks.Open(fPath & fCSV)
wbMST.Sheets(ActiveSheet.Name).Delete
ActiveSheet.Move After:=wbMST.Sheets(wbMST.Sheets.Count)
Columns.AutoFit
fCSV = Dir
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Set wbCSV = Nothing
End Sub
这做导入,但在我的csv文件的分隔符是分号和脚本使用逗号分隔符和表格变得混乱,因为逗号是在表格的标题中使用,并作为一个小数分隔符。我该如何改变它?
2条答案
按热度按时间sqserrrh1#
@罗恩Rosenfeld谢谢你,这个成功了。现在我只需要把我所有的数据文件都改成. txt。
up9lanfz2#
这样如何?