我在文件夹(和子文件夹)中有3,000张图片,我想在不同的Excel列中导入以下属性
档案名称
文件地址
图像宽度(以像素为单位)
excels中的图像高度
图片链接
如何使用VBA做到这一点?
感谢。
答案 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