如何将图像属性从Windows文件夹导入Excel列

时间:2016-01-25 08:01:18

标签: excel vba excel-vba

我在文件夹(和子文件夹)中有3,000张图片,我想在不同的Excel列中导入以下属性

  1. 档案名称

  2. 文件地址

  3. 图像宽度(以像素为单位)

  4. excels中的图像高度

  5. 图片链接

  6. 如何使用VBA做到这一点?

    感谢。

3 个答案:

答案 0 :(得分:0)

这将为您提供文件名,地址和图像链接的列表。

   Sub Macro1()

    Path = "C:\Pictures\"

    FileName = Dir(Path & "*.*")

    Do While Len(FileName) > 0
        Filename = Dir
        ActiveSheet.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = Filename
        ActiveSheet.Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Value = Path & Filename
        ActiveSheet.Hyperlinks.Add Anchor:=ActiveSheet.Range("B" & Rows.Count).End(xlUp), Address:="""" & Path & Filename & """", TextToDisplay:=Path & Filename
    Loop

    End Sub

答案 1 :(得分:0)

以下代码将文件夹中的所有图片带到Excel工作表...

Sub Macro2()
Dim Pic As Picture
Dim Path As String    
Dim FileName As String
Path = "C:\Pictures\"
FileName = Dir(Path & "*.*")
Do While Len(FileName) > 0
    Sheets.Add After:=Sheets(ActiveWorkbook.Sheets.Count)
    xFileName = Replace(FileName, ".png", "")   'or jpg
    ActiveSheet.Name = xFileName
    Set Pic = ActiveSheet.Pictures.Insert(Path & FileName)
    FileName = Dir
Loop
End Sub

答案 2 :(得分:0)

以下代码获取图片尺寸...

Sub Makro3()
Dim ws As Worksheet
For Each ws In Worksheets
    ws.Select
    Dim shp As Shape
    For Each shp In ws.Shapes
        MsgBox "Height: " & shp.Height & " Width: " & shp.Width
    Next shp
Next
End Sub