PDA

View Full Version : Reading/writing MP3 properties with Excel VBA



msrikanthjob
05-17-2012, 02:20 AM
Hello all,
I got the following code from this very form. I tried to run this, but i am getting an error with line
Dim id3 as New CddbID3Tag
I use vba with excel 2007
I am trying to read/write mp3 properties. Also the following code doesnot have information about the path?
I hope someone can help me out on this one..

Public Sub ProcessCells()
Dim id3 As New CddbID3Tag
Dim LastRow As Long
Dim i As Long

With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To LastRow
MP3TagChange id3, .Cells(i, "A")
Next i
End With
End Sub

Private Sub MP3TagChange(ByRef id3 As CddbID3Tag, ByRef cell As Range)
With cell
id3.LoadFromFile .Value, False
id3.Album = .Offset(0, 1).Value
id3.Title = .Offset(0, 4).Value
id3.LeadArtist = .Offset(0, 5).Value
id3.Year = .Offset(0, 6).Value
id3.Genre = .Offset(0, 7).Value
id3.TrackPosition = .Offset(0, 8).Value
id3.SaveToFile .Value
End With
End Sub
Thanks
Sri

Bob Phillips
05-17-2012, 02:47 AM
Presumably you have to set a reference to a particular library. Didn't it mention this where you got the code from?

msrikanthjob
05-17-2012, 03:05 AM
Thank You James. There was info about the path. I failed to remove that line by mistake.

but I couldnt get it working with the CddbID3Tag
could you please help with this.

Thanks
James.

msrikanthjob
05-17-2012, 03:12 AM
Hello James,
Thanks for your quick response.

Pardon me. I didnot delete that particular line from my message. A2 will be the path location.

Could you please help me with error in line
Dim id3 as New CddbID3Tag.
I believe its because of the missing dll. Is that true?
Is there anyother way i could come around this.

Looking forward to hear from you
Thanks
Sri

Bob Phillips
05-17-2012, 03:13 AM
James is James Thurber, not me. It is a quote.

As I said, the article should have told you which library to reference.

msrikanthjob
05-17-2012, 03:22 AM
hi,
I looked at that link. I couldnt find anything about library.

For quick reference i have link below:
vbaexpress.com/forum/showthread.php?t=19684

Thanks
Sri

msrikanthjob
05-17-2012, 03:31 AM
i get compile error, user defined data type not declared.

Bob Phillips
05-17-2012, 04:05 AM
It tells you which dll there, cddbcontrol.dll. CDDB is the Compact Disc Database, which holds details of millions of discs. As I recall it was provided by a company called GraceNote and you had to register to use it, If you google it you should find it no problem

snb
05-17-2012, 04:56 AM
You don't need any reference if you are using:

http://www.snb-vba.eu/VBA_Bestanden_en.html#L64

msrikanthjob
05-17-2012, 11:40 PM
Thanks for the information.
I do not have sufficient privilages to change system files like dlls so looked into link of vba for smarties.., I am a basic vba user.
the link seems to be only useful for getting the properties information rather than being able to change them.
I couldnt get it working

maneesh2312
10-23-2012, 05:01 AM
Hi All,

I've been trying to work on this piece of code to update MP3 tags and I was successful in getting through all the error expect that the id3.SaveToFile method is actually not saving the tags information in the MP3 files on local drive. Here's my code below.

Sub Change_MP3_Tags()

Dim objID3 As Object

Set objID3 = CreateObject("CDDBControl.CddbID3Tag")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDir = objFSO.GetFolder("C:\Users\ma16282\Music\Bittoo Boss")
Set objFiles = objDir.Files
Set objOrg = ThisWorkbook.Sheets("Original")
Set objEdit = ThisWorkbook.Sheets("Edit")

For a = 2 To 1000
If Trim(objOrg.Cells(a, 2).Value) <> "" Then
If Trim(objOrg.Cells(a, 2).Value) = "Yes" Then
strFile = Trim(objOrg.Cells(a, 3).Value)
For b = 2 To 1000
If Trim(objEdit.Cells(b, 2).Value) <> "" Then
If Trim(objEdit.Cells(b, 2).Value) = strFile Then
objID3.LoadFromFile Trim(objEdit.Cells(b, 2).Value), False
objID3.Album = Trim(objEdit.Cells(b, 6).Value)
objID3.Title = Trim(objEdit.Cells(b, 5).Value)
objID3.LeadArtist = Trim(objEdit.Cells(b, 7).Value)
objID3.Year = Trim(objEdit.Cells(b, 10).Value)
objID3.Genre = Trim(objEdit.Cells(b, 11).Value)
objID3.SaveToFile Trim(objEdit.Cells(b, 2).Value)
Exit For
End If
Else
Exit For
End If
Next
End If
Else
Exit For
End If
Next

End Sub


where "objEdit.Cells(b, 2).Value" contains the file name. Please see that the LoadFromFile and SaveToFile methods takes only file name as arguments and when I tried giving the full file path in both the methods, it gave an error saying "Method 'SaveToFile' of object 'ICddbID3Tag' failed". Why does this happen? Why is it not taking the full file path as a valid argument? I guess unless it take the full file path, the info will not be updated. If that is not the case, what is the solution to save the Tags in MP3 files?

Any help in this regard will be highly appreciated.

Thanks
Maneesh