Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to write extended headers? 1

Status
Not open for further replies.

stduc

Programmer
Nov 26, 2002
1,903
GB
I know how to retrieve the extended headers for a file using
objFolder.GetDetailsOf(strFileName, I)
Where I varies from 0 to 34 depending which header you want.

So one can retrieve such items as:-
Date modified
Attributes
Owner
File description


etc.

Is it possible to update this data using VBA? For example change the title of an mp3 file from a spreadsheet?

I have done quite a bit of research and found nothing so i fear not. But thought I would ask anyway.
 
yes is is possible. I'm nowhere near a PC at the moment so won't be able to provide an example for a bit.
 
Before commencing on this, many of the extended headers are simply derived from underlying properties of the file and so cannot be set (for example the file name). So which ones do you want to change?

 
At the moment.

For music files (specifically mp3 file)

Contributing artists
Album
Year
Genre
Conductors
Authors
Title
Subject
Categories
Comments
#


I may want to do something similar for video files at some point.

For general files - i.e. word documents

Company
File description

I am fascinated to read your solution.
 
>Contributing artists
Album
Year
Genre
Conductors
Authors
Title
Subject
Categories
Comments

Ok - the problem here is that these are data from within the MP3 file, so we actually need to know how to read/write MP3 data ...

 
OK - so which extended headers can you update from VBA?
 
I'm making a little progress. I found some code that looks like it might work for music files but it requires CDDBControlRoxio.dll.
I did have Roxio at one time for XP - back in 2006. So I installed it on a virtual machine and copied CDDBControlRoxio.dll from that machine to my real system32 folder. When I tried to register it though using regsvr32 it failed. The error message implies the file was either not found or there is a dll dependency somewhere. Now I'm at a loss again as to what to try next.
 
Beginning to win here - I managed to register CDDBControlRoxio.dll by NOT having it in system32! What's that about - anyway - here is my working code to date.

Code:
Sub Update_File_List()
'==========================================================================================================
'- MACRO TO CHANGE EXTENDED FILE PROPERTIES OF .MP3 AND .WMA FILES IN WINDOWS EXPLORER
'- Reads from amended worksheet prepared with separate "Build_File_List" macro module.
'==========================================================================================================
'- .WMA files do not have track number column 4
'- this version uses CDDBControlRoxio.dll version 2.4.1.9 and Excel 2007 running on Windows 7 64 bit
'- (was unable to get CDDBControl.dll version 2.6.101.101 to work)
'- Suggest you copy some files to a special folder for testing first.
'- Steve Duckworth September 2011 based on a routine by....
'- Brian Baulsom May 2008  - using Excel 2000/Windows XP
'==========================================================================================================
'==========================================================================================================
'- Method  (works on all files in a single folder)
'- 1. Run macro "Build_File_List" (other module) TO GET FILE NAMES INTO CURRENTLY ACTIVE WORKSHEET
'- 2. Amend file details in the worksheet. (Columns with names in BOLD only!)
'- 3. Run macro "Update_File_List" below.
'- N.B. This workbook assumes it is in the same folder as the music files
'==========================================================================================================
Dim ws As Worksheet
Dim Row As Long
Dim FQFN$
Dim MyFileType As String        ' mp3 wma etc.
Dim CurPath As String
Dim id3 As Object
'==========================================================================================================
'- MAIN ROUTINE
'- Run down visible rows and change data
'==========================================================================================================

'    Application.Calculation = xlCalculationManual
    CurPath = ActiveWorkbook.Path
'    CurName = ActiveWorkbook.Name
    Sheets("File List").Select
    Set ws = ActiveSheet
    Set id3 = CreateObject("CDDBControlRoxio.CddbID3Tag")
'    Set id3 = CreateObject("CDDBControl.CddbID3Tag")
    Row = 2
    '-----------------------------------------------------------------------------------------------------
    '- LOOP WORKSHEET FILES - VISIBLE ROWS ONLY
    Do Until Cells(Row, 1).Value = ""
        FQFN$ = CurPath & "\" & Cells(Row, 1)
        MyFileType = UCase(Right(FQFN$, 3))
        '- Write to file
        With id3
            .LoadFromFile FQFN$, False     ' True = Read Only
            .LeadArtist = Cells(Row, 14)    'Contributing Artists
            .Album = Cells(Row, 15) 'Album
            .Year = Cells(Row, 16)  'Track Year
            .Genre = Cells(Row, 17) 'Genre
''''            .Composer = Cells(Row, 21) 'Composers aka Author
''''            .ArtistFullname = Cells(Row, 21) 'Composers aka Author
            .Title = Cells(Row, 22) 'Track Title
            .Comments = Cells(Row, 25) 'Comments (N.B. these are NOT loaded by the read macro
            If MyFileType = "MP3" Then .TrackPosition = Cells(Row, 27)  'Track or #
            .SaveToFile FQFN$
        End With
        Row = Row + 1
        '---------------------------------------------------------------------------------------------
    Loop
    '-----------------------------------------------------------------------------------------------------
    '- end of program
''    Application.Calculation = xlCalculationAutomatic
 ''   rsp = MsgBox("Done" & vbCr & "Changed " & FilesChanged & " of " & FilesToChange)
  ''  Application.StatusBar = False
End Sub

As you can see - it is still a work in progress. It would be nice to be able to fill in the composers field - which fails with the error "Object doesn't support this property or method"

Any help offered accepted with gratitude.

Many thanks for strongm for pointing me in the right direction.
 
Whenever I run into a problem where something that is in a with statement doesn't work it usually means a previous identifier is missing.

For example

with Range("A1").font
.bold
End with

won't work but

with Range("A1").font
.fontstyle = "Bold"
End with

Does work.

I am guessing that you needs something like .fontstyle

Follow me?
 
Er .... no. I think you may have posted in the wrong thread ...
 
Not much use with PM3 files PHV.
 
Here's an example of reading the tag data without using a 3rd party DLL.
Code:
[blue]Option Explicit

[green]' Classic ID3V1.1 tag[/green]
Private Type ID3V1Tag
    Header         As String * 3
    Title       As String * 30
    Artist      As String * 30
    Album       As String * 30
    Year        As String * 4
    Comment     As String * 28
    Zero_byte   As Byte
    Track       As Byte
    Genre       As Byte [green]' you need a lookup table for this[/green]
End Type

Public Sub Example(strFile As String)
    Dim ID3Tag As ID3V1Tag
    Dim hFile As Long
   

    hFile = FreeFile()
    Open strFile For Binary As hFile
    Get hFile, LOF(hFile) + 1 - Len(ID3Tag), ID3Tag [green]' Tag, if it exists, is always at end of file[/green]
    Close hFile
    
    With ID3Tag
        If .Header = "TAG" Then [green]' have we got an ID3Tag?[/green]
            Debug.Print .Title
            Debug.Print .Artist
            Debug.Print .Album
            Debug.Print .Year
            Debug.Print .Comment
            If .Zero_byte = 0 Then Debug.Print Trim(.Track)
            Debug.Print Trim(.Genre)
        End If
    End With
   
End Sub[/blue]



Note that writing the data is simply a question of writing the UDF back at exactly the same plae you read it from in the file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top