因此,我有制表符分隔的CSV文件。 我有更改文件的内容宏,然后使用它的代码保存:打开制表符分隔的CSV并保存为制表符分隔
wb.Close SaveChanges:=True
的问题是,那么它被保存为一个CSV逗号分隔。
当另一个例程打开文件时,它会变得混乱。
我环顾四周,我没有找到一种方法将文件另存为Excel中的TAB分隔CSV。
有人可以帮助我吗?以下是完整的代码:
Sub routine()
Dim wb As Workbook
Dim Path As String 'Caminho
Dim File As String 'Arquivo da pasta
Dim Folder As FileDialog 'Pasta de origem
Dim answer As Integer
'-------------------------------------------------------------------------------'
answer = MsgBox("This macro will ask you to select a folder and change all the files from that folder. This action is not reversible, so make a backup before proceeding.", vbYesNo + vbInformation, "Confirm Action")
If answer = vbYes Then
Set Folder = Application.FileDialog(msoFileDialogFolderPicker)
With Folder
.Title = "Select Folder with CSV Files"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
Path = .SelectedItems(1) & "\"
End With
'Caso o usuário cancele
NextCode:
Path = Path
If Path = "" Then GoTo Resetar
File = Dir(Path & "*.csv*")
Do While File <> ""
Set wb = Workbooks.Open(Filename:=Path & File)
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, TrailingMinusNumbers:= _
True
Range("N:N, M:M, L:L, K:K, J:J, H:H, G:G, F:F, D:D, C:C ").EntireColumn.Delete
Range("A2").EntireRow.Delete
wb.sav
wb.Close SaveChanges:=True
DoEvents
File = Dir
Loop
MsgBox "CSV Files From Folder Updated"
Else
GoTo Resetar
Resetar:
MsgBox "User Cancelled Action"
End If
End Sub
TAB分隔文件是一个文本文件,您应该使用txt或tsv扩展名。 CSV是一个逗号分隔值文件,也是一个文本文件。 – Reeza