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.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Here are some helper methods to read from/write to the ID3 tag of an MP3 file.

Place the code below into a module, and then you can call the methods like this...

To get the artist:
strLeadArtist = GetTagItem("C:\Users\John\Music\Like a Rolling Stone.mp3", LeadArtist)

To set the artist:
SetTagItem "C:\Users\John\Music\Like a Rolling Stone.mp3", LeadArtist, "Bob Dylan"

You could also call the methods within a loop if you want to read/write multiple MP3 tags at once.

Code:
Public Enum TagItem
  Album
  BeatsPerMinute
  Comments
  CopyrightHolder
  CopyrightYear
  FileId
  Genre
  ISRC
  Label
  LeadArtist
  Movie
  PartOfSet
  Title
  TrackPosition
  Year
End Enum

Public Function GetTagItem(ByVal Path As String, ByVal Item As TagItem) As String
  Dim id3Tag As Object ' CDDBCONTROLLib.CddbID3Tag
  Set id3Tag = CreateObject("CDDBControl.CddbID3Tag")
  id3Tag.LoadFromFile Path, True
  Select Case Item
    Case Album: GetTagItem = id3Tag.Album
    Case BeatsPerMinute: GetTagItem = id3Tag.BeatsPerMinute
    Case Comments: GetTagItem = id3Tag.Comments
    Case CopyrightHolder: GetTagItem = id3Tag.CopyrightHolder
    Case CopyrightYear: GetTagItem = id3Tag.CopyrightYear
    Case FileId: GetTagItem = id3Tag.FileId
    Case Genre: GetTagItem = id3Tag.Genre
    Case ISRC: GetTagItem = id3Tag.ISRC
    Case Label: GetTagItem = id3Tag.Label
    Case LeadArtist: GetTagItem = id3Tag.LeadArtist
    Case Movie: GetTagItem = id3Tag.Movie
    Case PartOfSet: GetTagItem = id3Tag.PartOfSet
    Case Title: GetTagItem = id3Tag.Title
    Case TrackPosition: GetTagItem = id3Tag.TrackPosition
    Case Year: GetTagItem = id3Tag.Year
  End Select
  Set id3Tag = Nothing
End Function

Public Sub SetTagItem(ByVal Path As String, ByVal Item As TagItem, ByVal Value As String)
  Dim id3Tag As Object ' CDDBCONTROLLib.CddbID3Tag
  Set id3Tag = CreateObject("CDDBControl.CddbID3Tag")
  id3Tag.LoadFromFile Path, False
  Select Case Item
    Case Album: id3Tag.Album = Value
    Case BeatsPerMinute: id3Tag.BeatsPerMinute = Value
    Case Comments: id3Tag.Comments = Value
    Case CopyrightHolder: id3Tag.CopyrightHolder = Value
    Case CopyrightYear: id3Tag.CopyrightYear = Value
    Case FileId: id3Tag.FileId = Value
    Case Genre: id3Tag.Genre = Value
    Case ISRC: id3Tag.ISRC = Value
    Case Label: id3Tag.Label = Value
    Case LeadArtist: id3Tag.LeadArtist = Value
    Case Movie: id3Tag.Movie = Value
    Case PartOfSet: id3Tag.PartOfSet = Value
    Case Title: id3Tag.Title = Value
    Case TrackPosition: id3Tag.TrackPosition = Value
    Case Year: id3Tag.Year = Value
  End Select
  id3Tag.SaveToFile Path
  Set id3Tag = Nothing
End Sub
 
Upvote 0
I can't help with VBA. But there are programs that extract metadata like MP3 tags and create an Excel spreadsheet. TagScanner is a music app that can export MP3 tags as csv files. You can then manipulate the data using Excel or PowerQuery.
 
Upvote 0
I can't help with VBA. But there are programs that extract metadata like MP3 tags and create an Excel spreadsheet. TagScanner is a music app that can export MP3 tags as csv files. You can then manipulate the data using Excel or PowerQuery.

Thanks. I looked at Tag&Rename but it does not fit my requirements.
 
Upvote 0
Here are some helper methods to read from/write to the ID3 tag of an MP3 file.

Place the code below into a module, and then you can call the methods like this...

To get the artist:
strLeadArtist = GetTagItem("C:\Users\John\Music\Like a Rolling Stone.mp3", LeadArtist)

To set the artist:
SetTagItem "C:\Users\John\Music\Like a Rolling Stone.mp3", LeadArtist, "Bob Dylan"

You could also call the methods within a loop if you want to read/write multiple MP3 tags at once.

Code:
Public Enum TagItem
  Album
  BeatsPerMinute
  Comments
  CopyrightHolder
  CopyrightYear
  FileId
  Genre
  ISRC
  Label
  LeadArtist
  Movie
  PartOfSet
  Title
  TrackPosition
  Year
End Enum

Public Function GetTagItem(ByVal Path As String, ByVal Item As TagItem) As String
  Dim id3Tag As Object ' CDDBCONTROLLib.CddbID3Tag
  Set id3Tag = CreateObject("CDDBControl.CddbID3Tag")
  id3Tag.LoadFromFile Path, True
  Select Case Item
    Case Album: GetTagItem = id3Tag.Album
    Case BeatsPerMinute: GetTagItem = id3Tag.BeatsPerMinute
    Case Comments: GetTagItem = id3Tag.Comments
    Case CopyrightHolder: GetTagItem = id3Tag.CopyrightHolder
    Case CopyrightYear: GetTagItem = id3Tag.CopyrightYear
    Case FileId: GetTagItem = id3Tag.FileId
    Case Genre: GetTagItem = id3Tag.Genre
    Case ISRC: GetTagItem = id3Tag.ISRC
    Case Label: GetTagItem = id3Tag.Label
    Case LeadArtist: GetTagItem = id3Tag.LeadArtist
    Case Movie: GetTagItem = id3Tag.Movie
    Case PartOfSet: GetTagItem = id3Tag.PartOfSet
    Case Title: GetTagItem = id3Tag.Title
    Case TrackPosition: GetTagItem = id3Tag.TrackPosition
    Case Year: GetTagItem = id3Tag.Year
  End Select
  Set id3Tag = Nothing
End Function

Public Sub SetTagItem(ByVal Path As String, ByVal Item As TagItem, ByVal Value As String)
  Dim id3Tag As Object ' CDDBCONTROLLib.CddbID3Tag
  Set id3Tag = CreateObject("CDDBControl.CddbID3Tag")
  id3Tag.LoadFromFile Path, False
  Select Case Item
    Case Album: id3Tag.Album = Value
    Case BeatsPerMinute: id3Tag.BeatsPerMinute = Value
    Case Comments: id3Tag.Comments = Value
    Case CopyrightHolder: id3Tag.CopyrightHolder = Value
    Case CopyrightYear: id3Tag.CopyrightYear = Value
    Case FileId: id3Tag.FileId = Value
    Case Genre: id3Tag.Genre = Value
    Case ISRC: id3Tag.ISRC = Value
    Case Label: id3Tag.Label = Value
    Case LeadArtist: id3Tag.LeadArtist = Value
    Case Movie: id3Tag.Movie = Value
    Case PartOfSet: id3Tag.PartOfSet = Value
    Case Title: id3Tag.Title = Value
    Case TrackPosition: id3Tag.TrackPosition = Value
    Case Year: id3Tag.Year = Value
  End Select
  id3Tag.SaveToFile Path
  Set id3Tag = Nothing
End Sub
thank you, works like a charm, but do you know what the right name is for album artist?
 
Upvote 0
I realize this is thread is old thus I may not get any response from the participants, but here goes:
I am mainly interested in the TrackPosition tag for my project, and by using the posted code I can read that tag and get the same result as what Windows File Explorer or a tag editing utility shows. However, I cannot seem to edit the tag value using that code, which does not raise an error when I try. I can verify this by looking at the # column in FE and by using a tag editor utility afterwards and the tag remains the same before and after the code runs. Tag editing programs do edit the tag though.

I may get asked why I need to do this, and the answer is, I intend to create an Access db to capture my mp3 titles and will use a tag editing app to fix the song titles. However, I want to use vba to modify the TrackPosition tag to match the first 2 characters of the song titles (e.g. "03") because my car can present song lists by artist, folder or alpha titles. I want those lists to all be the same wrt position. A tag app will set the track position according to its position on an album, but some folders contain songs from different albums. Thus I will end up with mp3 files having the same track position, which will then sort by alpha, not by the position I want.

I suspect the problem with the code is that ID3 tags these days may have a version which has changed since that code was posted and may not gel with the posted code. Hoping someone can help.
 
Upvote 0
@Micron

Hi. By track position, do you mean track number metadata info in the playlist ?

Also, found in the details tab of the file Properties as highlighted in the following image :

PlayList.png
 
Upvote 0
Yes. That is how it shows in File Explorer. The ID3 tag property is called TrackPosition. If I could figure out why I can read that property (using the posted code) but can't edit it that would be great. There are other threads where using CddbControlRoxio.dll was a solution so I tried to download and register that file but it seems it is dependent upon another dll. Windows regsvr32 doesn't reveal dependencies when it fails . There are utilities you can install to determine dependencies but I don't want to go down that road. I think that the problem with most of these tag editing threads is that they're so old. I figure that has something to do with the fact that many codes don't work anymore.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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