Read & Write Mp3 File Tag Properties(solved)

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
About a year ago I posted a pair of macros to read/write MP3 tags. The Read macro puts file data into a worksheet for making changes, the Write macro uses the worksheet to change the files.The problem with the Write macro was that, although it did work, it used SendKeys which has to be slowed down considerably.

Here is a new version of the Write macro that works as normal. I originally tried to use CDDBControl.dll version 1.2.0.51 which is widely available on the internet but found that I could only get it to change 1 file before crashing Excel. There is a later version 2.0.0.6 but I could not find a download. You might have better success. In "fuzzy" searching for a replacement I found CDDBControlRoxio.dll on my own computer ( I own some of their software) which seems to function the same - except that it actually works. If you have problems with the .dll there seem to be several around with similar names that could be tried. The .dll needs to be registered on your computer by running regsvr32 followed by its file name.

I have put the READ macro in the next message.
Code:
'==========================================================================================================
'- MACRO TO CHANGE EXTENDED FILE PROPERTIES OF .MP3 AND .WMA FILES IN WINDOWS EXPLORER
'- Reads from amended worksheet prepared with separate "READ_FROM_EXPLORER" macro module.
'==========================================================================================================
'- .WMA files do not have track number column 4
'- this version uses CDDBControlRoxio.dll
'- (was unable to get CDDBControl.dll version 1.2.0.51 to change more than 1 file without crashing)
'- Suggest you copy some files to a special folder for testing first.
'- Brian Baulsom May 2008  - using Excel 2000/Windows XP
'==========================================================================================================
'==========================================================================================================
'- Method  (works on all files in a single folder)
'- 1. Run macro "READ_FROM_EXPLORER" (other module) TO GET FILE NAMES INTO CURRENTLY ACTIVE WORKSHEET
'- 2. Amend file details in the worksheet. Delete rows for files not changed to save time (can be left).
'- 3. Run macro "WRITE_TO_EXPLORER" below.
'==========================================================================================================
'- also uses Public variables in READ macro module
Dim ws As Worksheet
Dim FromRow As Long
Dim LastRow As Long
Dim FilesToChange As Integer    ' number of files to change
Dim FilesChanged As Integer        ' number of files changed
Dim MyFilePathName As String    ' full path & file name
Dim MyFileType As String        ' mp3 wma etc.
'-
Dim id3 As Object
Dim MyArtist As String
Dim MyAlbum As String
Dim MyGenre As String
Dim MyTrack As String
Dim MyTitle As String
'==========================================================================================================
'- MAIN ROUTINE
'- Run down visible rows and change data
'- worksheet has full path & file name in column O
'==========================================================================================================
Sub WRITE_TO_EXPLORER()
    Application.Calculation = xlCalculationManual
    Set ws = ActiveSheet
    Set id3 = CreateObject("CDDBControlRoxio.CddbID3Tag")
    '-----------------------------------------------------------------------------------------------------
    '- CHECK NUMBER OF FILES TO CHANGE (VISIBLE ROWS)
    LastRow = ws.Range("A65536").End(xlUp).Row  ' count worksheet rows
    FilesToChange = ws.Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible).Count
    If FilesToChange = 0 Then MsgBox ("No files to change."): Exit Sub
    FilesChanged = 0
    '-----------------------------------------------------------------------------------------------------
    '- LOOP WORKSHEET FILES - VISIBLE ROWS ONLY
    For FromRow = 2 To LastRow
        If ws.Cells(FromRow, "A").EntireRow.Hidden = False Then
            '---------------------------------------------------------------------------------------------
            '- Get file properties from sheet
            With ws
                    MyFilePathName = .Cells(FromRow, "O").Value
                    MyFileType = UCase(Right(MyFilePathName, 3))
                    Application.StatusBar = FileCount & "\" & FilesToChange & " " & MyFilePathName 'STATUSBAR
                    MyArtist = .Cells(FromRow, "B").Value
                    MyAlbum = .Cells(FromRow, "C").Value
                    MyTrack = .Cells(FromRow, "E").Value
                    MyGenre = .Cells(FromRow, "F").Value
                    MyTitle = .Cells(FromRow, "H").Value
            End With
            '---------------------------------------------------------------------------------------------
            '- Write to file
            With id3
                .LoadFromFile MyFilePathName, False     ' True = Read Only
                .LeadArtist = MyArtist
                .Album = MyAlbum
                .Genre = MyGenre
                .Title = MyTitle
                If MyFileType = "MP3" Then .TrackPosition = MyTrack
                .SaveToFile MyFilePathName
            End With
            '---------------------------------------------------------------------------------------------
            FilesChanged = FilesChanged + 1
        End If
    Next
    '-----------------------------------------------------------------------------------------------------
    '- end of program
    Application.Calculation = xlCalculationAutomatic
    rsp = MsgBox("Done" & vbCr & "Changed " & FilesChanged & " of " & FilesToChange)
    Application.StatusBar = False
End Sub
'======= END OF MAIN ======================================================================================
 
'Dim cdx As CDDBCONTROLLibRoxio.CddbID3Tag..... is ok


At the moment I get errors with ..
'Set id3 = CreateObject("CDDBControlRoxio.CddbID3Tag")
'Set id3 = New CDDBCONTROLLibRoxio.CddbID3Tag
However is there some similar but better dll vba compatable that will
write back the tags as from namespace folder items to More files
looking mainly at
Kind11
Date taken12
Year15
400
Keywords1013
MonthMod1014
FileExt1015
Folder name176
Folder path177
Drive1018
Path180
Title21
Comments24
Authors20
Tags18
Subject22
People246

<colgroup><col style="WIDTH: 71pt; mso-width-source: userset; mso-width-alt: 3008" width="94"><col style="WIDTH: 29pt; mso-width-source: userset; mso-width-alt: 1248" width="39"></colgroup><tbody>
</tbody>


to be writen to any file type... but mainly .xls and . jpg

Over about a year, I have been trying to get the above code, with modifications, to work and have had a bit of success.


Firstly, having no other knowledge of getting the information, I got a copy of CDDBControlRoxio.dll, renamed it as .txt, stripped all the non ascii characters, and replacing them with spaces. This gave me a text only version of the file, and from this I obtained the interfaces and thus the properties and methods. If anyone is interested, I will post same.


After getting the information, I tried all properties and found out which ones worked.


I then started back on my version of the spreadsheet (Excel 2003) and found that whilst single writes were successful, multiple updates to a single file mostly ended in a write error. Trapping this error enabled me to continue trying to write updated tag values.


I found that closing Excel completely and reopening / running the workbook resulted in a few successful updates before the write errors came up again. They appear to have issues with the same files, however a fresh restart usually results in 1 or 2 successful updates. This indicates to me a memory issue within Excel.


I then tried applying some methods I found ... and had moderate success ...


Placing a ".Commit" method after an assignment to a property reduces the write errors considerably. I have no idea what .Commit does but it works.


Example (based upon the original code):


.LoadFromFile MyFilePathName, False ' True = Read Only
.LeadArtist = MyArtist
.Commit
.Album = MyAlbum
.Commit
.Genre = MyGenre
.Commit
.Title = MyTitle
.Commit


Here is a list of properties and their corresponding GetDetailsOf reference:
Property GetDetailsOf reference number
.Title 21
.Album 14
.LeadArtist 13 or 20
.Genre 16
.CopyrightHolder 25
.Label 195
.Year 15
.TrackPosition 26


Other properties available for writing (CDDBControlRoxio.dll):
.CopyrightYear = "1999"
.FileId = "AB-12-34567"
.ISRC = "CD-34-56789"
.PartOfSet = "1"
.BeatsPerMinute = "12"


I have not been able to get CDDBControl.dll to work at all.
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I have recently started processing MP3 files again because I am digitising some old vinyl records.
I am using Shell because I discovered that it now has 296 properties available (not all are applicable - includes things for video etc.)
The properties are listed at the end of the code. There are so many that it is possible to use some and call them something else.
Please note - due to time restrictions I have just copy/pasted. Some of the code here (to map drive-I use this on other networked computers) will not be needed and can be removed.
Code:
'=====================================================================================
'- READ FILE PROPERTIES USING SHELL
'- (SHELL HAS 296 PROPERTIES LISTED AT THR END OF THE CODE
'=====================================================================================
'- Need to set 'BaseFolder' variable
Dim objNetwork As Object
Public Const BaseFolder As String = "Z:\ALBUMS"
Const Drv As String = "Z:"        ' Map Drive letter
Const ShareFolder As String = "\\BRIAN-PC\ALBUMS"
Dim ShareExists As Boolean
Dim ThisComputerName As String
'======================================================
Public ReadingFiles As Boolean
Dim MySheet As Worksheet
Dim ToRow As Long
Dim LastRow As Long
'----------------------------------------------
Dim FSO As Object           ' FileSystemObject
Dim FolderName As String
Dim FolderPath As String
Dim FolderSpec As String
Dim FileSpec As String
'---------------------------------------------
'- Shell variables
Dim ShellObj As Shell
Dim shFolder As Folder
Dim shFolderItem As FolderItem
'---------------------------------------------
Dim FullName As String
Dim MyFile As String
Dim MyType As String
Dim MyAlbum As String
Dim MyTitle As String
Dim MyArtist As String
Dim MyGenre As String
Dim MyDuration
Dim MyBitrate
Dim MyModified
Dim MyCustom
Dim Counter As Long

'=====================================================================================
'- MAIN ROUTINE : CLEAR SHEET, SET START FOLDER & GET ITS FILES - THEN GET SUB FOLDERS
'=====================================================================================
Sub READ_FOLDERS_FILES()
    Set ShellObj = New Shell
    '=====================================================================================
    '- CHECK DRIVE EXISTS & MAP IF NECESSARY
    '=====================================================================================
    '- CHECK CHANGES
    rsp = MsgBox("Read files from : " & BaseFolder, vbOKCancel)
    If rsp = vbCancel Then Exit Sub
    '-------------------------------------------------------------------------------
    '- CHECK FOLDER EXISTS
    rsp = Dir(Drv)
    ShareExists = (rsp <> "")
    '-------------------------------------------------------------------------------
    '- MAP DRIVE
    If ShareExists = False Then
        ThisComputerName = Workbooks("Personal+.xls").Worksheets("Data").Range("ComputerName").Value
        If ThisComputerName <> "BRIAN-PC" Then
            On Error Resume Next
            Set objNetwork = CreateObject("WScript.Network")
            objNetwork.mapnetworkdrive Drv, ShareFolder
            If Err.Number = 0 Then
                MsgBox ("Drive " & Drv & ":/ Mapped")
            Else
                MsgBox ("Drive " & Drv & ":/ Failed")
                Exit Sub
            End If
            On Error GoTo 0
        End If
    End If
    '=====================================================================================
    '- READ FILE DATA
    '=====================================================================================
    ReadingFiles = True
    Counter = 0
    If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
    '- initialise variables
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set MySheet = Worksheets("Library")
    Application.Calculation = xlCalculationManual
    ChDrive BaseFolder
    ChDir BaseFolder
    '-----------------------------------------------------------------------------------
    '- set up worksheet
    With MySheet
        LastRow = .Range("A65536").End(xlUp).Row
        If LastRow > 4 Then
            .Range("A5:Q" & LastRow).ClearContents
        End If
    End With
    ToRow = 5
    Application.ScreenUpdating = False
    '--------------------------------------------------------------------------------
    '- CALL FILE SUBROUTINE FOR BASE FOLDER
    Application.StatusBar = BaseFolder
    ShowFileList (BaseFolder)
    '-------------------------------------------------------------------------------
    '- CALL FOLDER SUBROUTINE (WHICH CALLS THE FILE ROUTINE)
    ShowFolderList (BaseFolder)
    '-------------------------------------------------------------------------------
    '- FINISH
    ReadingFiles = False
    Beep
    Application.ScreenUpdating = True
    Application.Goto Range("A5"), True
    MsgBox ("Done")
    Application.Calculation = xlCalculationAutomatic
    Application.StatusBar = False
End Sub
'========  END OF MAIN ROUTINE =======================================================

'=====================================================================================
'- SUBROUTINE : GET SUBFOLDERS OF SPECIFIED FOLDER
'=====================================================================================
Private Sub ShowFolderList(FolderSpec)
    Dim f, f1, fc, s
    Set f = FSO.GetFolder(FolderSpec)
    Set fc = f.SubFolders
    'If InStr(1, FolderSpec, "beatles", vbTextCompare) <> 0 Then Stop
    '---------------------------------------------------------------------------------
    '- CHECK SUBFOLDER COUNT
    If fc.Count = 0 Then
        Exit Sub
    Else
        '- LOOP FOLDERS
        For Each f1 In fc
            FolderName = f1.path
            Application.StatusBar = "***** " & FolderName
            ShowFileList (FolderName)
            '-----------------------------------------------------------------------
            '- CALL SELF TO GET ANY SUBFOLDERS IN THIS SUBFOLDER
            ShowFolderList (FolderName)
            '------------------------------------------------------------------------
        Next
    End If
    '--------------------------------------------------------------------------------
End Sub
'-
'=====================================================================================
'- SUBROUTINE : TO LIST FILES IN FOLDER
'=====================================================================================
Private Sub ShowFileList(FileSpec)
    Dim f, f1, fc, Spec
    Set f = FSO.GetFolder(FileSpec)
    Set fc = f.Files
    '--------------------------------------------------------------------------------
    '- CHECK FILE COUNT
    If fc.Count = 0 Then
        Exit Sub
    Else
        '-------------------------------------------------------------------------------------------------------
        Set shFolder = ShellObj.Namespace(FileSpec)
        '-------------------------------------------------------------------------------------------------------
        '- LOOP FILES
        For Each f1 In fc
            MyFile = f1.Name
            MyType = LCase(Right(MyFile, 3))
            If MyType = "mp3" Or MyType = "wma" Then
                Counter = Counter + 1
                FullName = FileSpec & "\" & MyFile
                Application.StatusBar = Counter & " : " & FullName
                '-----------------------------------------------------------------------------------------------
                c = InStrRev(FileSpec, "\", -1, vbTextCompare)
                MyFolder = Right(FileSpec, Len(FileSpec) - c)
                Set shFolderItem = shFolder.ParseName(MyFile)
                MyTitle = shFolder.GetDetailsOf(shFolderItem, 21)
                MyGenre = shFolder.GetDetailsOf(shFolderItem, 16)
                MyArtist = shFolder.GetDetailsOf(shFolderItem, 13)
                MyAlbum = shFolder.GetDetailsOf(shFolderItem, 14)
                MyDuration = shFolder.GetDetailsOf(shFolderItem, 27)
                MyBitrate = shFolder.GetDetailsOf(shFolderItem, 28)
                MyModified = shFolder.GetDetailsOf(shFolderItem, 3)
                '-------------------------------------------------
                'MyCustom = shFolder.GetDetailsOf(shFolderItem, 195)
                'If MyCustom = "" Then MyCustom = " " ' space
                '-----------------------------------------------------------------------------------------------
                Set Spec = FSO.GetFile(f1)  ' individual file info
                With MySheet
                    .Cells(ToRow, "A").Value = MyTitle
                    .Cells(ToRow, "B").Value = MyArtist
                    .Cells(ToRow, "C").Value = MyGenre
                    .Cells(ToRow, "E").Value = MyFolder
                    .Cells(ToRow, "F").Value = MyAlbum
                    .Cells(ToRow, "G").Value = f1.Name
                    .Cells(ToRow, "H").Value = MyType
                    .Cells(ToRow, "I").Value = MyDuration
                    .Cells(ToRow, "J").Value = DateValue(Spec.DateCreated)
                    .Cells(ToRow, "K").Value = DateValue(MyModified)
                    .Cells(ToRow, "L").Value = Spec.Size   'bytes
                    .Cells(ToRow, "M").Value = MyBitrate
                    .Cells(ToRow, "N").Value = FullName
                    .Cells(ToRow, "O").Value = MyCustom
                End With
                DoEvents
                ToRow = ToRow + 1
            End If
        Next
    End If
    '----------------------------------------------------------------------------------------------------------
End Sub
'=== END OF PROJECT =============================================================================================


'- SHELL FILE PROPERITES
'0   Name
'1   Size
'2   Item type
'3   Date Modified
'4   Date created
'5   Date accessed
'6   Attributes
'7   Offline Status
'8   Offline availability
'9   Perceived type
'10  owner
'11  Kind
'12  Date taken
'13  Contributing artists
'14  Album
'15  Year
'16  Genre
'17  Conductors
'18  Tags
'19  rating
'20  Authors
'21  Title
'22  Subject
'23  Categories
'24  Comments
'25  copyright
'26  #
'27  Length
'28  Bit Rate
'29  Protected
'30  Camera model
'31  Dimensions
'32  Camera maker
'33  Company
'34  File Description
'35  Program Name
'36  Duration
'37  Is online
'38  Is recurring
'39  Location
'40  Optional attendee addresses
'41  Optional attendees
'42  Organizer Address
'43  Organizer Name
'44  Reminder Time
'45  Required attendee addresses
'46  Required attendees
'47  Resources
'48  Meeting Status
'49  Free/busy status
'50  Total Size
'51  Account Name
'52  task Status
'53  computer
'54  Anniversary
'55  Assistant 's name
'56  Assistant 's phone
'57  Birthday
'58  Business Address
'59  Business City
'60  Business Country / region
'61  Business P.O.box
'62  Business postal code
'63  Business State Or province
'64  Business Street
'65  Business fax
'66  Business home page
'67  Business phone
'68  Callback Number
'69  Car phone
'70  Children
'71  Company main phone
'72  Department
'73  E-mail address
'74  e -mail2
'75  e -mail3
'76  E-mail list
'77  E-mail display name
'78  File as
'79  First Name
'80  Full Name
'81  Gender
'82  Given Name
'83  Hobbies
'84  Home Address
'85  Home City
'86  Home Country / region
'87  Home P.O.box
'88  Home postal code
'89  Home State Or province
'90  Home Street
'91  Home fax
'92  Home phone
'93  IM addresses
'94  Initials
'95  Job Title
'96  Label
'97  last Name
'98  Mailing Address
'99  Middle Name
'100 Cell phone
'101 Nickname
'102 Office Location
'103 Other Address
'104 Other City
'105 Other Country / region
'106 Other P.O.box
'107 Other postal code
'108 Other State Or province
'109 Other Street
'110 Pager
'111 Personal Title
'112 City
'113 Country/region
'114 P.O.box
'115 Postal code
'116 State or province
'117 Street
'118 Primary e - mail
'119 Primary phone
'120 Profession
'121 Spouse/Partner
'122 Suffix
'123 TTY/TTD phone
'124 Telex
'125 Webpage
'126 Content Status
'127 Content type
'128 Date acquired
'129 Date archived
'130 Date completed
'131 Device Category
'132 Connected
'133 Discovery Method
'134 Friendly Name
'135 Local computer
'136 Manufacturer
'137 model
'138 Paired
'139 Classification
'140 Status
'141 Client ID
'142 Contributors
'143 Content created
'144 last printed
'145 Date last saved
'146 Division
'147 Document ID
'148 Pages
'149 Slides
'150 Total editing time
'151 Word Count
'152 Due Date
'153 End date
'154 File Count
'155 FileName
'156 File Version
'157 flag Color
'158 flag Status
'159 Space free
'160 Bit Depth
'161 Horizontal resolution
'162 Width
'163 Vertical resolution
'164 Height
'165 Importance
'166 Is attachment
'167 Is deleted
'168 Encryption Status
'169 Has flag
'170 Is completed
'171 Incomplete
'172 Read Status
'173 Shared
'174 Creators
'175 Date
'176 Folder Name
'177 Folder Path
'178 Folder
'179 Participants
'180 Path
'181 by Location
'182 Type
'183 Contact Names
'184 Entry type
'185 Language
'186 Date visited
'187 Description
'188 link Status
'189 link Target
'190 URL
'191 Media created
'192 Date released
'193 Encoded by
'194 Producers
'195 Publisher
'196 Subtitle
'197 User web URL
'198 Writers
'199 attachments
'200 Bcc addresses
'201 Bcc
'202 Cc addresses
'203 Cc
'204 Conversation ID
'205 Date Received
'206 Date sent
'207 From addresses
'208 From
'209 Has attachments
'210 Sender Address
'211 Sender Name
'212 Store
'213 To addresses
'214 To do title
'215 To
'216 Mileage
'217 Album artist
'218 Album ID
'219 Beats -per - Minute
'220 Composers
'221 Initial Key
'222 Part of a compilation
'223 Mood
'224 Part of set
'225 Period
'226 Color
'227 Parental rating
'228 Parental rating reason
'229 Space used
'230 EXIF Version
'231 Event
'232 Exposure bias
'233 Exposure Program
'234 Exposure Time
'235 F-stop
'236 Flash Mode
'237 Focal Length
'238 35mm focal length
'239 ISO speed
'240 Lens maker
'241 Lens model
'242 Light Source
'243 Max aperture
'244 Metering Mode
'245 Orientation
'246 People
'247 Program Mode
'248 saturation
'249 Subject distance
'250 White Balance
'251 Priority
'252 Project
'253 Channel Number
'254 Episode Name
'255 Closed captioning
'256 Rerun
'257 SAP
'258 Broadcast Date
'259 Program Description
'260 Recording Time
'261 Station call sign
'262 Station Name
'263 Summary
'264 Snippets
'265 Auto Summary
'266 Search ranking
'267 Sensitivity
'268 Shared with
'269 Sharing Status
'270 Product Name
'271 Product Version
'272 Support link
'273 Source
'274 Start Date
'275 Billing Information
'276 Complete
'277 task owner
'278 Total file size
'279 Legal trademarks
'280 Video compression
'281 Directors
'282 Data Rate
'283 Frame Height
'284 Frame Rate
'285 Frame Width
'286 Total bitRate
'287 Primary disk
'288 Memory
'289 Machine Status
'290 Configuration File
'291
'292
'293
'294
'295 Masters Keywords (debug)
'296 Masters Keywords (debug)
'
 
Upvote 0
Hi Brian, I used your code to change metadata .mp3, incorporating this an option to rename files, but to run it changes the information from the first Excel file and then stops working.
A second consultation, the CDDBControlRoxio.dll file or CDDBControl.dll allows me to change very few records regarding all existing metadata, there is another .dll file that you refer me?
Thank you
 
Upvote 0
Don't understand your question.
My latest version uses Shell instead, as indicated.
I am still using this today.
 
Upvote 0
Thanks Brian, I found a new version of cddbcontrol.dll with which I have no more problems.

The other question is in relation to the amount of metadata that supports the cddbcontrol, ie can only handle 15 items (Album, BeatsPerMinute, Comments, CopyrightHolder, CopyrightYear, Field, Genre, ISRC, Label, LeadArtist, Movie, PartOfSet, Title, TrackPosition and Year), but the shell is over 200, and can change over 15 items?
 
Upvote 0
I have been trying to use the code, but i cant figure out why it dosnt work....
i havent been coding VBA for some years now and is a bit rusty.
 
Upvote 0

Forum statistics

Threads
1,215,102
Messages
6,123,099
Members
449,096
Latest member
provoking

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