Excel VBA-用于根据单元格值检测文件是否存在的函数 [英] Excel VBA - Function to detect if a file exists based on Cell Values

查看:83
本文介绍了Excel VBA-用于根据单元格值检测文件是否存在的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Trying to write a function to detect if a file (pdf) exists. Due to there being a number of files/folders I'd like to build the filepath from cell values.

到目前为止,我已经知道了:

I've got this so far:

Public Function FileExists(FullpathName As String) As Boolean

If Len(Dir(FullpathName)) = 0 Then

    FileExists = True

Else

    FileExists = False

End If

End Function

我要在单元格中输入此内容:

And I'm entering this in the cell:

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

,但是当文件确实在其中时,它将返回为false.谁能阐明我所缺少的东西?

but it's returning it as false when the file is definitely in there. Can anyone shed some light on what I'm missing?

谢谢!

推荐答案

您的 IF 条件倒退,请使用:

Your IF condition is backwards, use:

Public Function FileExists(FullpathName As String) As Boolean
    If Len(Dir(FullpathName)) = 0 Then
        FileExists = False
    Else
        FileExists = True
    End If
End Function

这篇关于Excel VBA-用于根据单元格值检测文件是否存在的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆