Excel VBA用户定义的function在文件夹中查找图像

我在Excel表中的图像名称为:

16094_1.jpg 16095_1.jpg,16095_2.jpg 

在逗号分隔的单元格中名称可以是单个或多个。 他们存储在位置

 "C:\Users\Jatin\Desktop\Jatin\november\17-nov\images" 

我想创build用户定义的函数(公式),可以find图像在所需的位置,无论它们是否存在。 例如,

 =findimage("path",imagename) =findimage("C:\Users\Jatin",a1) 

在这里输入图像说明

 Function hasImages(Path As String, ImageList As String) Dim results Dim x As Long results = Split(ImageList, ",") If Not Right(Path, 1) = "\" Then Path = Path & "\" For x = 0 To UBound(results) results(x) = Len(Dir(Path & results(x))) > 0 Next hasImages = Join(results, ",") End Function 

你可以试试这个function:

 Function IfFileExist(strPath As String, strFileName As String) IfFileExist = False If Len(Dir(strPath & "\" & strFileName)) > 0 Then IfFileExist = True End If End Function