Sub ReformatForALFA()
Filename = Dir("C:\Users\Daisy\Desktop\Cloudy\*.*")
Do While Len(Filename) > 0
Workbooks.Open (Filename)
row_num = Range(Cells(1, 1), Cells(1, 1).End(xlDown)).Rows.Count
myRng = Empty
For i = 1 To row_num
If myRng = Empty And Cells(i, 1) Like "*value*row*" = False Then
myRng = Rows(i).Address()
ElseIf Cells(i, 1) Like "*value*row*" = False Then
myRng = myRng & "," & Rows(i).Address()
Else
Pos1 = InStr(Cells(i, 1), "=") + 2
Pos2 = InStr(Cells(i, 1), ">") - 1
Pos3 = InStr(Cells(i, 1), "/") - 1
Age = Mid(Cells(i, 1), Pos1, Pos2 - Pos1)
Num = Mid(Cells(i, 1), Pos2 + 2, Pos3 - (Pos2 + 2))
Cells(i, 2) = Age
Cells(i, 3) = Num
End If
Next i
Range(myRng).Delete
Columns(1).EntireColumn.Delete
Filename = Dir()
Loop
End Sub
您好,我上面写了一个宏来遍历文件夹中的所有文本文件。该文件夹中有两个文本文件。当我运行它时,它显示“我们找不到Tuesday.txt,因为它已被删除,移动等等。任何人都可以帮我解决这个问题。谢谢!雏菊
Filename = Dir("C:\Users\Daisy\Desktop\Cloudy\*.*")
将只检索没有路径的文件名。您可以使用chdir更改为路径,也可以添加要打开的文件的路径
ChDir ("C:\Users\Daisy\Desktop\Cloudy")
要么
Workbooks.open("C:\Users\Daisy\Desktop\Cloudy\" & filename)