简体   繁体   English

VBA优于jpg类型的图像格式的存在

[英]VBA excel for existence of image format of type jpg

Lets say that I have a spreadsheet in excel named test.xls and inside it a column named column1 with values image1, image2, etc. And I have a folder named images, contain images of type jpg, named like the values in the column image1.jpg, image2.jpg, etc. I need a Vba code to check if the images exist in the folder based on the spreadsheet column. 可以说我在excel中有一个名为test.xls的电子表格,里面有一个名为column1的列,其值为image1,image2等。我有一个名为images的文件夹,包含jpg类型的图像,名称类似于image1中的值.jpg,image2.jpg等我需要一个Vba代码来检查图像是否存在于基于电子表格列的文件夹中。 Thank you! 谢谢!

This example will display the search results in another column. 此示例将在另一列中显示搜索结果。 Edit the variables and don't forget the last \\ in the folder path. 编辑变量,不要忘记文件夹路径中的最后一个\\。

Sub checkFiles()
  Dim count&, lastRow&
  Dim folderPath, columnRead, columnWrite As String

  folderPath = "C:\EXAMPLE\"
  columnRead = "A"
  columnResults = "B"

  lastRow = ThisWorkbook.Sheets(1).Range(columnRead & Rows.count).End(xlUp).Row
  For count = 1 To lastRow
    Range(columnRead & count).Activate

    If Dir(folderPath & Range(columnRead & ActiveCell.Row).Value) <> "" Then
        Range(columnResults & ActiveCell.Row).Value = "File exists."
    Else
        Range(columnResults & ActiveCell.Row).Value = "File doesn't exist."
    End If

  Next count
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM