|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
下面程序只能调用计算机硬盘的JPG文件,不能调用手机里的图片。
- Sub lll()
- Dim Sht As Worksheet
- Dim Rng As Range
- Set Sht = Sheet1
- ''Debug.Print Sht.Cells.Rows.Count
- Set Rng = Sht.Range("B1:AZ65536")
- Rng.Clear
- Sht.Cells.Font.Size = 9
- Rr = Sht.Range("A6566").End(xlUp).Row
- Rr = 5
- Set Rng = Sht.Cells(Rr, 1)
- TraverserJPG Rng, ThisWorkbook.Path ' & "\JPG"
- End Sub
- Function TraverserJPG(Rng As Range, Path)
- Dim xlWk As Workbook
- Dim xlSht As Worksheet
- 'Set xlWk = ConnectWk("F:\日出日落时间\中国东西南北城市.xlsm")
-
- Dim Sht As Worksheet
- Dim Fso As Scripting.FileSystemObject
- Dim oFile As File, oFilesAs As Files
- Dim oFolder As Folder
- Dim Img As WIA.ImageFile
- Dim oDate As Date
- Dim Rr, Cc
- Dim Str
- Set Img = New WIA.ImageFile
- Set Sht = Rng.Parent
- 'Set xlSht = xlWk.Worksheets("珠海") 'Sht.Cells(Rng.Row, 1))
- Rr = 10 'Rng.Row + 2
-
- Set Fso = New Scripting.FileSystemObject
- 'Debug.Print Path
- Set oFolder = Fso.GetFolder(Path)
- ''
- For Each oFile In oFolder.Files
- Cc = 2
- 'If InStr(oFile.Type, "JPEG") > 0 Then
- 'If InStr(oFile.Type, "JPG") > 0 Then
- If InStr(oFile.Name, "IMG") > 0 Then
-
- With Sht
- Img.LoadFile oFile.Path
- '.Cells(Rr, Cc + 1) = oFile.Name
- 'Debug.Print oFile.Name, oFile.ParentFolder.Name, oFile.ParentFolder.ShortPath
- .Cells(Rr, Cc + 9) = oFile.DateLastModified
- 'Str = oFile.DateLastModified
- oDate = .Cells(Rr, Cc + 9)
- .Cells(Rr, Cc + 15) = Format(oDate, "yyyy年m月d日 ")
- Str = Format(oDate, "[$-C04]dddd mm dd,yyyy ;@") & _
- Format(oDate, "hh:mm:ss")
- Str = Format(oDate, "[$-3409]dddd, mmmm dd, yyyy, ;@ ")
- Str = Str & Format(oDate, "[$-409]h:mm:ss AM/PM;@")
- .Cells(Rr, Cc + 1) = Str
- Str = Format(oDate, "yyyy年m月d日 ") & _
- Format(oDate, " [$-zh-CN]aaaa;@") & Format(oDate, " h时mm分ss秒 ;@") 'Format(oDate, "[$-409]AM/PM h:mm:ss;@")
- 'Format(oDate, " [$-zh-CN]aaaa;@") & Format(oDate, " [$-zh-CN]上午/下午h时mm分ss秒 ;@") 'Format(oDate, "[$-409]AM/PM h:mm:ss;@")
- Cc = Cc + 1
- .Cells(Rr, Cc + 1) = Str
- .Cells(Rr, Cc + 2) = GetYLDate(oFile.DateLastModified)
- .Cells(Rr, Cc + 6) = oFile.Name
- .Cells(Rr, Cc + 3) = Format(Int(oFile.Size / 1024), "0,000")
- .Cells(Rr, Cc + 7) = "" & oFile.ParentFolder.Name & ""
- .Cells(Rr, Cc + 4) = Img.Width
- .Cells(Rr, Cc + 5) = Img.Height
- .Cells(Rr, Cc + 8) = oFile.Type
- .Cells(Rr, Cc + 12) = oFile.Path
- .Cells(Rr, Cc + 13) = Img.Width
- .Cells(Rr, Cc + 14) = Img.Height
-
- End With
- End If
- Rr = Rr + 1
- Next oFile
- Set Rng = Sht.Cells(Rr + 2, 1)
- ''
- For Each oFolder In oFolder.SubFolders
- TraverserJPG Rng, oFolder.Path
- Next oFolder
- 'xlWk.Close
- End Function
复制代码
网上找了半天,好像不能直接处理手机里的图片,只能将手机里的图片,拷贝或移动到硬盘才能处理JPG图片。
|
|