Issues with a VBA code for excel that takes the geolocation info longitude latitude altitude from a set of files in a folder

0 votes

Thus, I created this code for my task that directly extracts the geotag data from a group of image files' properties in a folder that is specified in the excel file (so it can be applied to different folders). Each file's file name, longitude, latitude, and altitude are supposed to be copied and pasted into a new row in the Excel worksheet. I'm currently experiencing an Error 424: Object Needed. I'm not sure what is wrong with the code or whether I'm simply overlooking anything simple. I've tried other codes I've found on Stack and online as well but they didn't work the way I needed either so I ended up trying to make it myself using those as a reference.

Any help is much appreciated.

Here is the full code I have for this task:

Sub ExtractPhotoData()

    'Declare variables
    Dim FSO As Object
    Dim SourceFolder As Object
    Dim FileItem As Object
    Dim Image As Object
    Dim RowCounter As Integer
    
    'Set up the file system object and source folder
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set SourceFolder = Worksheets("Sheet2").Cells(2, 9).Value
    
    'Loop through each file in the source folder
    For Each FileItem In SourceFolder.Files
    
        'Check if the file is an image
        If InStr(1, FileItem.Type, "image") > 0 Then
        
            'Load the image
            Set Image = CreateObject("WIA.ImageFile")
            Image.LoadFile FileItem.Path
            
            'Extract the longitude, latitude, and altitude data
            Dim Longitude As String
            Dim Latitude As String
            Dim Altitude As String
            Longitude = Image.Properties("GPS Longitude").Value
            Latitude = Image.Properties("GPS Latitude").Value
            Altitude = Image.Properties("GPS Altitude").Value
            
            'Paste the data into the worksheet
            RowCounter = RowCounter + 1
            Cells(RowCounter, 1).Value = FileItem.Name
            Cells(RowCounter, 2).Value = Longitude
            Cells(RowCounter, 3).Value = Latitude
            Cells(RowCounter, 4).Value = Altitude
        
        End If
    
    Next FileItem

End Su
Mar 21, 2023 in Others by narikkadan
• 63,420 points
374 views

1 answer to this question.

0 votes
SourceFolder is an object that only understands excel sheets because it is specified to be a worksheet (set SourceFolder = Work...). It does not handle files. Thus, we must loop on the FSO rather than the SourceFolder. Change the loop's format to FSO, however when you do so, I believe it will require initialization to tell it which directory to start in.
answered Mar 21, 2023 by Kithuzzz
• 38,010 points

Related Questions In Others

0 votes
1 answer

Creating a function in excel VBA to calculate the average point in a circular set of numbers

I used the following code to determine ...READ MORE

answered Oct 28, 2022 in Others by narikkadan
• 63,420 points
843 views
0 votes
1 answer
0 votes
1 answer

VBA code help - Add a line for each missing date with the start and end date defined in a cell

Try this: Sub FillDates() Dim ...READ MORE

answered Jan 24, 2023 in Others by narikkadan
• 63,420 points
656 views
0 votes
1 answer

Looping through a folder with Excel files and scraping date from selected cells usin VBA

You record the outcome of your comparison ...READ MORE

answered Feb 16, 2023 in Others by narikkadan
• 63,420 points
656 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
909 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,229 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
519 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,670 points
761 views
0 votes
1 answer

Excel VBA: Obtain the Column and Row of current element in "For Each" loop

Try this: MsgBox rng.Address(RowAbsolute:=False, ColumnAbsolute:=F ...READ MORE

answered Feb 14, 2023 in Others by Kithuzzz
• 38,010 points
779 views
0 votes
1 answer

Select data that meet criteria from a table, adding it to a combobox in userform VBA Excel

Fill Combo Box With Matches Sub GetSourceAcc() ...READ MORE

answered Mar 26, 2023 in Others by Kithuzzz
• 38,010 points
467 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP