首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么我的通配符不能通过目录注册?

为什么我的通配符不能通过目录注册?
EN

Stack Overflow用户
提问于 2019-05-24 02:13:12
回答 1查看 60关注 0票数 0

我有一个子文件夹循环脚本,用于确定Cells(2,3)是否为空,如果为空,则继续删除该列。

我有一个通配符*,这样就不需要命名任何文件,只需要命名扩展名。为什么这一行:MyFile = "*.xlsx"不能提取实际的文件名?它只是在循环中显示为*.xlsx,并退出sub,因为什么都没有找到。

基于答案的编辑代码:

Sub LoopSubfoldersAndFiles()

    Dim folder As Object
    Dim subfolders As Object
    Dim MyFile As String
    Dim wb As Workbook
    Dim currentfile As Object, currentfolder As Object

    With Application
    .ScreenUpdating = False
    .EnableEvents = False
    .Calculation = xlCalculationManual
    End With


    Set subfolders = folder.subfolders
    MyFile = "*.xlsx"

    For Each subfolders In subfolders

    Set CurrentFile = subfolders.Files

    With New FileSystemObject ' reference Microsoft Scripting Runtime library

        Dim root As folder
        Set root = .GetFolder("C:\Users\pp87255\Desktop\JNav Rest\05.23.2019")

        Dim subFolder As folder
        For Each subFolder In root.subfolders

            Dim currentfolder As folder
            For Each currentfolder In subFolder.subfolders

                Dim currentfile As File
                For Each currentfile In currentfolder.Files
                    If currentfile.Name Like "*.xlsx" Then
                        Dim wb As Workbook
                        Set wb = Application.Workbooks.Open(currentfile.Path)
                        If wb.Sheets(1).Cells(2, 3).Value2 = "" Then
                            Columns(3).EntireColumn.Delete
                        End If
                    End If
                Next
            Next
        Next
    End With


    Next

    Set folder = Nothing
    Set subfolders = Nothing

With Application
    .EnableEvents = True
    .Calculation = xlCalculationAutomatic
    .ScreenUpdating = True
End With

End Sub
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56280838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档