0

我正在为我的 VBA 代码的一部分寻求帮助。它在少数 PC 上运行没有任何问题,但在我的电脑上它根本不起作用。没有返回错误。如果有人看到可能有问题的地方,请告诉我。

fn = Dir(ThisWorkbook.Path & "\*.xl*")
Do While ((fn <> "") And (Not (fn Like "*Inside*")))

    Range("B4").value = fn

    Call setCorrectValues

    fn = Dir()
Loop
4

1 回答 1

0

最近遇到了该死的 Dir 函数的麻烦。尝试这个:

Dim objFSO As Variant
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim FolderName As String
FolderName = ThisWorkbook.Path

Dim objFolder As Variant
Set objFolder = objFSO.GetFolder(FolderName)
Debug.Print objFolder.Path

Dim objFiles As Variant
Set objFiles = objFolder.Files
Dim objFile As Variant
For Each objFile In objFiles
    Debug.Print objFile.Name
    If Not (fn Like "*Inside*.xls") Then
        Range("B4").Value = fn
        Call setCorrectValues
        Exit For
    End If
Next
于 2013-09-11T12:59:46.317 回答