Editing MP3 Tags

mdodge

Board Regular
Joined
May 3, 2004
Messages
97
MP3 files have imbedded metadata that I would like to edit. I have between 35K and 40K files that I would like to edit one or two fields in each. I would also like to export to an Excel database a selection of fields: Title, Artist, Comment and so on. I can open each individual file in File Explore and select Properties and edit the field but I could spend years doing that. Has anyone had any experience using VBA to automate the process? I have some experience with VBA over the years but the interface between Excel and File Explorer is my problem.
 
I can report that it compiled as is, but did nothing to my test folder. I'd say that's because none of the file names had a hyphen in them. Not sure why you made that a requirement? Maybe I can re-test tomorrow by circumventing that requirement.
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I managed to do some further testing after I changed to this
VBA Code:
For Each sFileName In oFolder.Files
    If UCase(oFso.GetExtensionName(sFileName.Path)) = "MP3" Then
        'lHyphenPos = InStr(sFileName.Name, "-")
        'If lHyphenPos > 1& Then
            'sExtractedNumFromFileName = Trim(Left(sFileName.Name, lHyphenPos - 1&))
        lHyphenPos = InStr(sFileName.Name, " ")
        sExtractedNumFromFileName = Clng(Left(sFileName.Name, lHyphenPos - 1))
        If IsNumeric(sExtractedNumFromFileName) Then
            If Set_MP3_TrackNumber_Value _
                (sMP3File:=sFileName.Path, NewValue:=CLng(sExtractedNumFromFileName)) Then
                lTotalFileTagsEdited = lTotalFileTagsEdited + 1&
            End If
        End If
    End If
    'End If
Next
I figure (for my case at least) best to get the first two characters of the file name and convert to Long so that 01 becomes 1 rather than trying to pass 01 to a variable that expects a long, thus the Clng function I inserted.Now if I could only figure out how to make this work in Access rather than having to use 2 apps for the project. Here's the result
1708565579018.png


EDIT - I just noticed that you did the Clng conversion during the passing of the file name characters so maybe not required. Will have to test, because during my first testing the very first file was skipped and the results started at position 2. That might have been a result of my Trim re-write part, which underwent a couple of revisions, so I'm not sure what fixed it.
 
Last edited:
Upvote 0
Not sure why you made that a requirement? Maybe I can re-test tomorrow by circumventing that requirement.
I did that based on the first screen shot you posted ... In order to edit the TrackNumber tag of each mp3 file, I needed some way of extracting the corresponding number that preceeds the hyphen showing on the file name hence the code I posted.

But in order to ensure that the Set_MP3_TrackNumber_Value function works , we can simply carry out an easy test on a single mp3 file without any of the above mentioned complications as follows :

VBA Code:
Sub Test2()

    Dim sMP3File As String
 
    sMP3File = "C:\Users\hp\Music\Playlists\test.mp3"  '<< change filepathname to suit.
 
    'edit the mp3 file tracknumber tag with some random value (for example 1234)
    Call Set_MP3_TrackNumber_Value(sMP3File:=sMP3File, NewValue:=1234)

End Sub
 
Last edited:
Upvote 0
I figured as much wrt the hyphen. I guess I wasn't clear enough when I addressed that
My apologies - I made an image from a poor sample folder because that folder has not be formatted yet.

I will fix the file names via various edits, to remove hyphens, octothorpes, whatever. I will end up with ##+space+filename including the mp3 extension.
Your code seems to work great and I cannot thank you enough. Wish I understood more of it. Since it works in Excel I figure I will use Access to organize and fix file names, and rather than use Automation to control Excel from Access I might as well just use the two apps and save myself from grief.

As a side note, you indicated this was some sort of project and I was thinking a userform might be a good idea. With that you could provide controls for defining such things as numeric prefixes (or not), their length (someone may have prefixes like 001 or even numbers above 99), what is the separator character, etc. Also, your test idea could produce a result using the parameters and display it in the form. If it doesn't look good, user could cancel and fix the parameters. Would make for a fairly robust app I think.

Again, thanks so much. I can add your name as a credit to the code if you like - in case I share an app with anyone.
 
Upvote 0
Hi Micron.

Just so you know, I wrote some generic code for reading and editing file metadata properties. This applies to any file type, not just mp3s.

I posted the code in this thread.

I hope it will be of benefit to vab users.

Regards.
 
Upvote 0
I will send you a pm about what's going on for me wrt this project.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top