[英]Excel Macro to search if content of a column (filename) exists in a folder
I have an excel sheet where I have the names of jpegs in columns F & G from rows 2 to 1800. I would like to use a macro in order to see if these Jpegs exist in a folder on my computer (mac) at a certain directory (ex. /user/Dropbox/Content/productinfo/pictures). 我有一个excel工作表,在第2行至1800行的F&G列中有jpegs的名称。我想使用一个宏来查看这些Jpegs是否存在于计算机(mac)上的某个文件夹中。目录(例如/ user / Dropbox / Content / productinfo / pictures)。 If they do exist i would like to return the value "exists", if not, then "doesnt".
如果它们确实存在,我想返回值“ exists”,如果不存在,则返回“ doesnt”。 The only issue is in a few cases no Jpeg exists in the spreadsheet so there is nothing to look up
唯一的问题是在某些情况下电子表格中不存在Jpeg,因此无需查找任何内容
I'm new to excel Macros. 我是excel宏的新手。 Please help me out!
请帮帮我!
Thanks in advance! 提前致谢!
Dim iCount As Integer
iCount = Application.WorksheetFunction.COUNTIF(Range("F2:G1800"),".jpg")
if iCount > 0 Then
'Do your checks
End If
You can use a user-defined function for that. 您可以为此使用用户定义的函数。 In you case, you can call the below using:
您可以使用以下方法致电:
=fileexists("C:\MyPath\"&f2)
Here's the function 这是功能
Public Function FileExists(sPath As String)
If lcase(right(sPath,5)) <> ".jpeg" Then
FileExists = ""
Else
If Len(Dir(sPath)) > 0 Then
FileExists = "Exists"
Else
FileExists = ""
End If
End If
End Function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.