麻辣家族討論版版's Archiver

HSIEN6001 發表於 2019-11-1 05:18

請問 Application.FileSearch '執行階段錯誤2455 ,請問這應該怎麼修改?

[code]Function 資訊()
    DoCmd.SetWarnings False   
    Dim Filename As Integer   

        Set BK = Application.FileSearch         '執行階段錯誤2455 ,請問這該怎麼改?
            With BK                             
            .LookIn = "D:\資訊-原始\"     
            .Filename = "all*.xls"   
                If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending) > 0 Then
                    For B = 1 To .FoundFiles.Count  
                    DoCmd.TransferSpreadsheet acImport, 8, "00 原始資料", .FoundFiles(B), True
                    Next
                End If
            End With
        Set BK = Nothing      

End Function[/code]

cody 發表於 2020-7-18 16:56

請問 office 版本?, 可以換 FileSystemObject 來用[code]Dim FSO As Object
Dim localfolder As String

Set FSO = CreateObject("Scripting.FileSystemObject")
localfolder = "D:\資訊-原始\"
Set fld = FSO.GetFolder(localfolder)

For Each myFileName In fld.Files
   
    If FSO.GetExtensionName(localfolder & myFileName.Name) = "xls" Then
        Debug.Print myFileName.Name
    End If
Next
[/code]

頁: [1]

麻辣家族討論版版為 麻辣學園 網站成員  由 昱得資訊工作室 © Since 1993 所提供