温馨提示:本文翻译自stackoverflow.com,查看原文请点击:excel - Invalid Procedure call or argument on Debug.Print

excel - 无效的过程调用或Debug.Print上的参数

发布于 2020-03-27 11:14:26

尝试使用几天前在这里收到的一些建议来重做我几天前做的函数...我在Debug.Print的行上收到一个无效的过程调用或参数。

VBA和Excel的新手。感谢您的帮助和耐心等待。

Public Sub GetSOPFiles()
    ' Set folder path
    Const FolderPath As String = "C:\Users\test\Desktop\SOP Excel Prototype"

    Const FileExt As String = "docx"

    Dim Result As Variant
    Dim i As Integer
    Dim MyFile As Object
    Dim MyFSO As Object
    Dim MyFolder As Object
    Dim MyFiles As Object
    Dim dept As Variant
    Dim deptCodes As Variant

    Set MyFSO = CreateObject("Scripting.FileSystemObject")
    Set MyFolder = MyFSO.GetFolder(FolderPath)
    Set MyFiles = MyFolder.Files

    Dim vData As Variant
    Dim sTemp As Variant

    ReDim vData(0 To MyFiles.Count - 1, 0 To 0)

    x = 1

    With MyFiles
        While x <= UBound(vData, 1)
            Debug.Print (MyFiles(x).Name)
        Wend
    End With
End Sub

查看更多

查看更多

提问者
mongoose00318
被浏览
92
BigBen 2019-07-04 00:46

MyFiles是一个集合,应使用For Each...Next循环对其进行迭代

Set MyFSO = CreateObject("Scripting.FileSystemObject")
Set MyFolder = MyFSO.GetFolder(FolderPath)
Set MyFiles = MyFolder.Files

For Each MyFile In MyFiles
    Debug.Print MyFile.Name ' no parentheses
Next

您无法索引到MyFiles集合中。For Each...NextFiles文档所述使用循环

发布
问题

分享
好友

手机
浏览

扫码手机浏览