我正在尝试使用Wayne Phillips的类模块代码(EXIFReader访问应用程序)和David Zemens在“Excel VBA打开文件夹并获取其中每个文件的GPS信息(Exif)”帖子中提出的子例程建议,从jpg文件中检索Exif元数据(嵌入在使用Nikon Coolpix W300相机拍摄的图片中的GPS纬度和经度数据)(原始帖子链接:如何使用VBA在Excel工作表中获取图片的EXIF信息)。
在David的回答指导下,我尝试了他提出的所有方法:
1)我将Wayne的类模块导入到我的工作簿项目中;
2)在类模块中,我修改了声明的函数,使用“PtrSafe”声明使其与Excel 64位兼容;
3)我在普通代码模块中创建了一个完全像David建议的子例程;
4)我已更新文件夹路径为正确的路径 (
调试代码时,当代码运行到第四行进入With/End With块,并执行“.GPSLatitudeDecimal”指令时,应用程序崩溃。 在关闭Excel应用程序之前没有出现错误消息。 我想了解这段代码出了什么问题,如何修复它并检索我需要制作月度照片报告的GPS元数据。
在David的回答指导下,我尝试了他提出的所有方法:
1)我将Wayne的类模块导入到我的工作簿项目中;
2)在类模块中,我修改了声明的函数,使用“PtrSafe”声明使其与Excel 64位兼容;
3)我在普通代码模块中创建了一个完全像David建议的子例程;
4)我已更新文件夹路径为正确的路径 (
Set fldr=fso.GetFolder("C:/users/david_zemens/desktop/")
)。
5) 我已经编译和调试了项目,当代码运行到存储在GPSExifProperties类模块中的以下指令时,我遇到了应用程序崩溃:
Property Get GPSLatitudeDecimal() As Variant Call **VCOMObject**.AssignVar(GPSLatitudeDecimal, VCOMObject.GPSLatitudeDecimal) End Property
Wayne的类模块代码可以在此链接中找到:https://www.everythingaccess.com/tutorials.asp?ID=Extracting-GPS-data-from-JPEG-files
我正在尝试使用的David Zemens代码如下:
Sub OpenFromFolder()
On Error GoTo ExifError
Dim strDump As String
'## REQUIRES REFERENCE TO MICROSOFT SCRIPTING RUNTIME
Dim fso As Scripting.FileSystemObject
Dim fldr As Scripting.Folder
Dim file As Scripting.file
Set fso = CreateObject("scripting.filesystemobject")
Set fldr = fso.GetFolder("E:\DNIT\Relatório Fotográfico\Fotos com dados GPS") '#### Modify this to your folder location
For Each file In fldr.Files
'## ONLY USE JPG EXTENSION FILES!!
Select Case UCase(Right(file.Name, 3))
Case "JPG"
With GPSExifReader.OpenFile(file.Path)
strDump = strDump & "FilePath: " & .FilePath & vbCrLf
strDump = strDump & "DateTimeOriginal: " & .DateTimeOriginal & vbCrLf
strDump = strDump & "GPSVersionID: " & .GPSVersionID & vbCrLf
strDump = strDump & "GPSLatitudeDecimal: " & .GPSLatitudeDecimal & vbCrLf
strDump = strDump & "GPSLongitudeDecimal: " & .GPSLongitudeDecimal & vbCrLf
strDump = strDump & "GPSAltitudeDecimal: " & .GPSAltitudeDecimal & vbCrLf
strDump = strDump & "GPSSatellites: " & .GPSSatellites & vbCrLf
strDump = strDump & "GPSStatus: " & .GPSStatus & vbCrLf
strDump = strDump & "GPSMeasureMode: " & .GPSMeasureMode & vbCrLf
strDump = strDump & "GPSDOPDecimal: " & .GPSDOPDecimal & vbCrLf
strDump = strDump & "GPSSpeedRef: " & .GPSSpeedRef & vbCrLf
strDump = strDump & "GPSSpeedDecimal: " & .GPSSpeedDecimal & vbCrLf
strDump = strDump & "GPSTrackRef: " & .GPSTrackRef & vbCrLf
strDump = strDump & "GPSTrackDecimal: " & .GPSTrackDecimal & vbCrLf
strDump = strDump & "GPSImgDirectionRef: " & .GPSImgDirectionRef & vbCrLf
strDump = strDump & "GPSImgDirectionDecimal: " & .GPSImgDirectionDecimal & vbCrLf
strDump = strDump & "GPSMapDatum: " & .GPSMapDatum & vbCrLf
strDump = strDump & "GPSDestLatitudeDecimal: " & .GPSDestLatitudeDecimal & vbCrLf
strDump = strDump & "GPSDestLongitudeDecimal: " & .GPSDestLongitudeDecimal & vbCrLf
strDump = strDump & "GPSDestBearingRef: " & .GPSDestBearingRef & vbCrLf
strDump = strDump & "GPSDestBearingDecimal: " & .GPSDestBearingDecimal & vbCrLf
strDump = strDump & "GPSDestDistanceRef: " & .GPSDestDistanceRef & vbCrLf
strDump = strDump & "GPSDestDistanceDecimal: " & .GPSDestDistanceDecimal & vbCrLf
strDump = strDump & "GPSProcessingMethod: " & .GPSProcessingMethod & vbCrLf
strDump = strDump & "GPSAreaInformation: " & .GPSAreaInformation & vbCrLf
strDump = strDump & "GPSDateStamp: " & .GPSDateStamp & vbCrLf
strDump = strDump & "GPSTimeStamp: " & .GPSTimeStamp & vbCrLf
strDump = strDump & "GPSDifferentialCorrection: " & .GPSDifferentialCorrection & vbCrLf
Debug.Print strDump '## Modify this to print the results wherever you want them...
End With
End Select
NextFile:
Next
Exit Sub
ExifError:
MsgBox "An error has occurred with file: " & file.Name & vbCrLf & vbCrLf & Err.Description
Err.Clear
Resume NextFile
End Sub
调试代码时,当代码运行到第四行进入With/End With块,并执行“.GPSLatitudeDecimal”指令时,应用程序崩溃。 在关闭Excel应用程序之前没有出现错误消息。 我想了解这段代码出了什么问题,如何修复它并检索我需要制作月度照片报告的GPS元数据。