如何遍历文件夹中的所有文件
2014-12-08 · 知道合伙人数码行家
关注
展开全部
您好,很高兴能帮助您
Private Sub Command1_Click()
Dim FileName As String, FilePath As String
Dim iFolder As Object, Xlapp As Object, Sh As Object
Set iFolder = CreateObject("shell.application").BrowseForFolder(0, "", 0, "")
If iFolder Is Nothing Then Exit Sub
FilePath = iFolder.Items.Item.Path
FilePath = IIf(Right(FilePath, 1) = "\", FilePath, FilePath & "\")
FileName = Dir(FilePath & "*.xls*")
Set Xlapp = CreateObject("excel.application")
Xlapp.displayalerts = False
Do Until Len(FileName) = 0
With Xlapp.workbooks.open(FilePath & FileName)
For Each Sh In .WORKSHEETS
If Len(Sh.RANGE("B2").Value) = 0 Then Sh.Delete
Next
.Close True
End With
FileName = Dir
Loop
Xlapp.quit
Set Xlapp = Nothing
End Sub
你的采纳是我前进的动力,
记得好评和采纳,答题不易,互相帮助,
Private Sub Command1_Click()
Dim FileName As String, FilePath As String
Dim iFolder As Object, Xlapp As Object, Sh As Object
Set iFolder = CreateObject("shell.application").BrowseForFolder(0, "", 0, "")
If iFolder Is Nothing Then Exit Sub
FilePath = iFolder.Items.Item.Path
FilePath = IIf(Right(FilePath, 1) = "\", FilePath, FilePath & "\")
FileName = Dir(FilePath & "*.xls*")
Set Xlapp = CreateObject("excel.application")
Xlapp.displayalerts = False
Do Until Len(FileName) = 0
With Xlapp.workbooks.open(FilePath & FileName)
For Each Sh In .WORKSHEETS
If Len(Sh.RANGE("B2").Value) = 0 Then Sh.Delete
Next
.Close True
End With
FileName = Dir
Loop
Xlapp.quit
Set Xlapp = Nothing
End Sub
你的采纳是我前进的动力,
记得好评和采纳,答题不易,互相帮助,
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询