簡體   English   中英

Excel宏以搜索文件夾中是否存在列(文件名)的內容

[英]Excel Macro to search if content of a column (filename) exists in a folder

我有一個excel工作表,在第2行至1800行的F&G列中有jpegs的名稱。我想使用一個宏來查看這些Jpegs是否存在於計算機(mac)上的某個文件夾中。目錄(例如/ user / Dropbox / Content / productinfo / pictures)。 如果它們確實存在,我想返回值“ exists”,如果不存在,則返回“ doesnt”。 唯一的問題是在某些情況下電子表格中不存在Jpeg,因此無需查找任何內容

我是excel宏的新手。 請幫幫我!

提前致謝!

Dim iCount As Integer
iCount = Application.WorksheetFunction.COUNTIF(Range("F2:G1800"),".jpg")

if iCount > 0 Then

  'Do your checks
End If

您可以為此使用用戶定義的函數。 您可以使用以下方法致電:

=fileexists("C:\MyPath\"&f2)

這是功能

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM