我在目录中有很多.csv文件。第四列(Number)之间有空格,如下例所示。如何仅从列中删除空格并将其应用于目录中的所有文件,而无需逐个打开每个文件。
"EMIS Number","Organisation Name","Organisation Code","Number","Date","Clinical Code","Code Term",
"11","West Hampstead Medical Centre","F03033","931 094 3111","19-Apr-1019","G340-1","Coronary artery disease",
"14","Prince Of Wales Medical Centre","F03010","401 300 1319","03-Jan-1004","G30","Acute myocardial infarction",
"13","HAMPSTEAD GROUP PRACTICE","F03014","411 419 3949","1999","G3","Ischaemic heart disease",
"19","BROOKFIELD PARK SURGERY","F03031","400 134 0101","1991","G3","Ischaemic heart disease",
P.S。我已经尝试过Excel和VBA,但它们都需要打开每个文件才能运行公式。我也尝试过UltraEdit但它会删除所有文件中的所有空格而不是一个特定的列。
答案 0 :(得分:1)
请参阅以下代码以循环浏览所有文件。
Sub OpenFiles()
Dim MyFolder As String
MyFolder = "Your Folder Name where all files are saved."
Dim MyFile As String
MyFile = Dir(MyFolder & "\*.csv")
Do While MyFile <> ""
Workbooks.Open Filename:=MyFolder & "\" & MyFile
Columns("D:D").Replace What:=" ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Activeworkbook.close true
MyFile = Dir
Loop
End Sub
打开文件后,添加代码以删除空间。