Update MP3 Tags Using Excel VBA

purceld2

Well-known Member
Joined
Aug 18, 2005
Messages
586
Office Version
  1. 2013
Platform
  1. Windows
I trying to find some VBA which updates mp3 tags. I have a very large MP3 collection and most of the tags need updating after some research I believe it is possible to export all the tag information to Excel. (Print Folders will do This). Use Excel tools to clean up data. Then use VBA to update the tags using the updated information in the spreadsheet.


I have looked around on the net and below is some VBA code which only go part way to doing the job. Could somebody assist me to enhance the code to do what I have described above please

Part Solution 1 (Which I have not texted)
I've been busy trying to figure out how to edit MP3 tags in Excel/VBA.
I've found a method which makes use of a DLL-file called cddbcontrol.dll.
Here's the code which is working for me :
Code:


VBA:

Sub MP3TagChange()
Sheets("MP3tags").Select
Dim id3 As New CddbID3Tag
id3.LoadFromFile Range("A2").Value, False
id3.Album = Range("B2").Value
id3.Title = Range("E2").Value
id3.LeadArtist = Range("F2").Value
id3.Year = Range("G2").Value
id3.Genre = Range("H2").Value
id3.TrackPosition = Range("I2").Value
id3.SaveToFile Range("A2").Value
End Sub

In A2 I have the full path to a MP3-file.
This code is working and the changes are being made to that file.[/vba]
What I'd like to do is to change this code, so that it changes the tags for all the Mp3's which are listed in Col A.
I hope someone can help me out on this one..

Thanks in advance,
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I have also found this code but does not seem to work on Windows 7 64 bit


Code:
 '============================================================================================================
'- READ .MP3 & .WMA FILE PROPERTIES TO A WORKSHEET
'============================================================================================================
'- MACRO TO :-
'- *1. SELECT A FOLDER -  *2. CLEAR THE ACTIVE WORKSHEET*  -  *3. READ .MP3 & .WMA EXTENDED FILE PROPERTIES*
'- *3. MAKES PROPERTY CELLS BLUE
'- ONLY EXTRACTS FILE DATA SO CAN BE USED ON ITS OWN. SHEETS CAN BE SAVED AS NORMAL
'- CAN THEN RUN MACRO "WRITE_TO_EXPLORER" (in another module below) TO *CHANGE* PROPERTIES
'- Uses Windows Shell32.dll (Requires Tools/References .. 'Microsoft Shell Controls And Automation')
'- Brian Baulsom July 2007 - using Excel 2000/Windows XP
' ==========================================================================================================
'- Method (works on all files in a single folder)
'- 1. Run macro "READ_FROM_EXPLORER" below TO GET FILE NAMES INTO CURRENTLY ACTIVE WORKSHEET
'- 2. Manually amend file details in the worksheet.Delete or hide rows for files not changed saves time(can be left)
'- 3. Run macro "WRITE_TO_EXPLORER" (other module)
'===========================================================================================================
Option Base 1                       ' MyProperties(15) starts 1 instead of 0
Dim MyFilePathName As String        ' Local variable full path & file name
Public MyPathName As String         ' **Public variable     |enables 'Sub GetPathFileNameFromFullPath()'|
Public MyFileName As String         ' **Public variable     |usage in 'WRITE_TO_EXPLORER' macro         |
'- Properties Array (list of integers)
Dim Arr1 As Variant                 ' "Name"= shell property zero + First 5 properties in Windows Explorer
Dim Arr2 As Variant                 ' some more shell GetDetailsOf() property numbers (0-34 available. 3 unused)
Dim MyProperties(16) As Integer     ' Shell property index numbers used here. Puts them in required order
Dim MyPropertyNum As Integer        ' Array item position 1-15
Dim MyPropertyVal As Variant        ' Lookup Array data shell property numbers 0,16, 17 ... etc.
'-
Dim ws As Worksheet
Dim ToRow As Long                   ' write to worksheet row number
'- Shell variables
Dim ShellObj As Shell
Dim MyFolder As Folder
Dim MyFolderItem As FolderItem
'-
'===========================================================================================================
'- MAIN ROUTINE
'===========================================================================================================
Sub READ_FROM_EXPLORER()
    Application.EnableEvents = False    ' WORKSHEET Worksheet_Change() makes changed cells yellow
    '-------------------------------------------------------------------------------------------------------
     '- GET FOLDER NAME FROM FIRST FOLDER\FILE IN THE WORKSHEET
    MyFilePathName = ActiveSheet.Range("O2").Value
    If InStr(1, MyFilePathName, "\", vbTextCompare) <> 0 Then 'there is "\" in the path
        GetPathFileNameFromFullPath (MyFilePathName)    ' PUBLIC SUBROUTINE IN 'READ_FROM_EXPLORER' module
        ChDrive MyPathName
        ChDir MyPathName & "\"
    Else
        ChDrive ThisWorkbook.FullName
        ChDir ThisWorkbook.FullName
    End If
    '- GET FOLDER - Method 1 - using Windows Dialog (comment out if not required)
    'MsgBox ("Selecting a single file in the following dialog gets the required *FOLDER*." & vbCr & vbCr _
             & "NB. CLEARS THE CURRENTLY ACTIVE SHEET.")
    MyFilePathName = _
        Application.GetOpenFilename("Audio Files (*.mp3;*.wma),*.mp3;*.wma", , "        GET FOLDER REQUIRED")
    If MyFilePathName = "False" Then Exit Sub
    GetPathFileNameFromFullPath MyFilePathName  ' subroutine to separate folder & file name
    '-------------------------------------------------------------------------------------------------------
'    '- GET FOLDER - Method 2 - hard coded for testing (comment out if not required)
'    MyPathName = "C:\TEMP\MP3_TEST"            ' SET AS REQUIRED
    '=======================================================================================================
    Set ShellObj = New Shell
    Set MyFolder = ShellObj.NameSpace(MyPathName)
    '------------------------------------------------------------------------------------------
    ChDrive MyPathName
    ChDir MyPathName & "\"
    Set ws = ActiveSheet
    ToRow = 2
    With ws.Columns("A:O").Cells
        .ClearContents                ' clear worksheet
        .Interior.ColorIndex = xlNone
    End With
    ws.Rows.Hidden = False
    '-------------------------------------------------------------------------------------------
    '- INITIALISE PROPERTY ARRAY. CLEAR & SET UP WORKSHEET
    '- Set up array to sort properties into the required order
    '- do not change Arr1 (list of changeable fields in Windows Explorer - used in WRITE macro.)
    '      "Name", "Artist", "Album", "Year", "Track", "Genre", "Lyrics", "Title","Comments")
    Arr1 = Array(0, 16, 17, 18, 19, 20, 27, 10, 14)
        For n = 1 To 9: MyProperties(n) = Arr1(n): Next
    '-     "Duration", "Size", "Date Modified", "Category", "Author", "Bit Rate"
    Arr2 = Array(21, 9, 12, 3, 1, 22, 33)
        For n = 10 To 16: MyProperties(n) = Arr2(n - 9): Next
    '-------------------------------------------------------------------------------------------
    '- write worksheet header
    For n = 1 To 14
        ws.Cells(1, n).Value = MyFolder.GetDetailsOf(MyFolder.Items, MyProperties(n))
    Next
    With ws
        '- "Lyrics" is not included in the Shell properties. I have used a blank one item 27
        .Cells(1, "G").Value = "Lyrics"
        '- This is useful for other purposes.  eg. to play the track via macro.
        .Cells(1, "O").Value = "Full Name"
        .Range("A1:O1").Interior.ColorIndex = 37    ' Dark blue header
    End With
    '===========================================================================================
    '- GET FILE NAMES & PROPERTIES FROM FOLDER
    '===========================================================================================
    MyFileName = Dir(mypath & "*.*")   'first file name
    Do While MyFileName <> ""
        '- filter .MP3 & .WMA
        If UCase(Right(MyFileName, 3)) = "MP3" Or UCase(Right(MyFileName, 3)) = "WMA" Then
            Set MyFolderItem = MyFolder.ParseName(MyFileName)
            '--------------------------------------------------------------------
            '- properties to worksheet
            For MyPropertyNum = 1 To 14
                MyPropertyVal = MyFolder.GetDetailsOf(MyFolderItem, MyProperties(MyPropertyNum))
                ws.Cells(ToRow, MyPropertyNum).Value = MyPropertyVal
            Next
            '---------------------------------------------------------------------
            '- add full path\file name (used as lookup by "WRITE_TO_EXPLORER")
            ws.Cells(ToRow, 15).Value = MyPathName & "\" & MyFileName
            ToRow = ToRow + 1
        End If
        MyFileName = Dir    ' Get next file name
    Loop
    '-------------------------------------------------------------------------------------------
    '- finish
    With ws
        .Activate
        '.UsedRange.Columns.AutoFit
        .Range("D1,G1,I1,K1").EntireColumn.Hidden = True
        .Range("A1").Select
    End With
    '-------------------------------------------------------------------------------------------
    '- colour editable range -> blue
    '-------------------------------------------------------------------------------------------
    If ToRow > 2 Then ws.Range("B2:I" & ws.Range("A2").End(xlDown).Row).Interior.ColorIndex = 34
    MsgBox ("Done.")
    Application.EnableEvents = True
End Sub
'=========== END OF MAIN ROUTINE ===============================================================
'===============================================================================================
'- SUB TO SEPARATE PATH & FILE NAME FROM FULL NAME
'- puts to Public module level variables 'MyFileName' & 'MyPathName'
'===============================================================================================
Public Sub GetPathFileNameFromFullPath(Nm As String)
    For c = Len(Nm) To 1 Step -1
        If Mid(Nm, c, 1) = "\" Then
            MyFileName = Right(Nm, Len(Nm) - c)
            MyPathName = Left(Nm, Len(Nm) - Len(MyFileName) - 1)
            Exit Sub
        End If
    Next
End Sub
'----------------------------------------------------------------------------------------------
 
Upvote 0
I am Setting Track Position for a group of MP3's. For MP3's where Bit rate is 64 kbps this Sub works fine; yet for MP3's where Bit rate is 128 kbps this Sub works fine until the 2nd iteration of the Do While Loop and errors out on the line
.LoadFromFile MyFileFullName, False

with error message:
Run-time error '-2147023170 (800706be)'
Automation error
The remote procedure call failed
---------------------------------
As far as I can tell the other MP3 file properties are the same in both groups of .MP3 files.
'***************************************************************************************************************************
Sub SetMP3FileProperties()

Dim id3 As Object
Dim MyFileFullName As String ' full path & file name

Dim MyNumber As Integer

Set id3 = CreateObject("CDDBControlRoxio.CddbID3Tag")
sDir = "C:\Users\BradPC\Music\AbbeyRoad\"

sFileName = Dir$(sDir & "\*.mp3")
MyNumber = 1 'Mid(sFileName, 1, 2)

Do While sFileName > ""
MyFileFullName = sDir & "\" & sFileName

' Write to file
With id3
.LoadFromFile MyFileFullName, False '<--here's where it errors on 2nd iteration of the Loop
.TrackPosition = MyNumber
.SaveToFile MyFileFullName
End With
MyNumber = MyNumber + 1
sFileName = Dir$
Loop

ThisWorkbook.Save

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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