1

尝试编写一个函数来检测文件(pdf)是否存在。由于有许多文件/文件夹,我想从单元格值构建文件路径。

到目前为止我有这个:

Public Function FileExists(FullpathName As String) As Boolean

If Len(Dir(FullpathName)) = 0 Then

    FileExists = True

Else

    FileExists = False

End If

End Function

我在单元格中输入了这个:

=FileExists(A2&B2&A3&" "&A1&" "&C2&".pdf")

但是当文件肯定在那里时,它会将其返回为假。任何人都可以阐明我所缺少的东西吗?

谢谢!

4

1 回答 1

3

您的IF条件是向后的,请使用:

Public Function FileExists(FullpathName As String) As Boolean
    If Len(Dir(FullpathName)) = 0 Then
        FileExists = False
    Else
        FileExists = True
    End If
End Function
于 2013-10-15T15:09:47.577 回答