Dan Wilson
Well-known Member
- Joined
- Feb 5, 2006
- Messages
- 546
- Office Version
- 365
- Platform
- Windows
Good day all. I am running Excel out of Office 365 (updated) on Windows 10 Home. A few months ago I was given a Macro to help with extracting File Properties from Music Files. After running this Macro several times I find that the code is dropping some files. My Music folder contains 4550 files. The Macro is showing 4438 files in a worksheet titled DB. Coincidentally, after the DB worksheet is created (10 minutes), executing a Control-End command selects Column G Row 4551 with Rows 4439 through 4551 being empty. The Control-End selects the correct location for having searched 4550 files with a header column. I have copied the Macro below if anyone wants to examine it to find a problem. I have tried editing the Macro to search a music folder with less than 100 songs and it works correctly. I appreciate any help. Thank you, Dan...
Sub get_file_properties_DB_1()
' 11/14/2020
Dim objShellApp As Object
Dim objFolder As Object
Dim varColumns As Variant
Dim arrData() As Variant
Dim strFilename As String
Dim fileCount As Long
Dim i As Long
Dim j As Long
Set objShellApp = CreateObject("Shell.Application")
Set objFolder = objShellApp.Namespace("C:\Users\Daniel\Music\MP3 Normalized") 'change the path to the source folder accordingly
varColumns = Array(0, 13, 15, 26, 27, 24, 16)
ReDim arrData(0 To UBound(varColumns), 0 To objFolder.Items.Count)
For i = LBound(arrData, 1) To UBound(arrData, 1)
arrData(i, 0) = objFolder.GetDetailsOf(objFolder.Items, varColumns(i))
Next i
fileCount = 0
For i = 0 To objFolder.Items.Count - 1
strFilename = objFolder.GetDetailsOf(objFolder.Items.Item(CLng(i)), 0)
If Right(strFilename, 4) = ".mp3" Or Right(strFilename, 4) = ".wav" Then
fileCount = fileCount + 1
For j = 0 To UBound(varColumns)
arrData(j, fileCount) = objFolder.GetDetailsOf(objFolder.Items.Item(CLng(i)), varColumns(j))
Next j
End If
Next i
Worksheets.Add
Columns("A:A").Select
Selection.NumberFormat = "@"
ActiveSheet.Name = "DB1"
Range("A1").Resize(UBound(arrData, 2) + 1, UBound(arrData, 1) + 1).Value = Application.Transpose(arrData)
Cells.Select
Selection.Columns.AutoFit
Range("A1").Select
End Sub
Sub get_file_properties_DB_1()
' 11/14/2020
Dim objShellApp As Object
Dim objFolder As Object
Dim varColumns As Variant
Dim arrData() As Variant
Dim strFilename As String
Dim fileCount As Long
Dim i As Long
Dim j As Long
Set objShellApp = CreateObject("Shell.Application")
Set objFolder = objShellApp.Namespace("C:\Users\Daniel\Music\MP3 Normalized") 'change the path to the source folder accordingly
varColumns = Array(0, 13, 15, 26, 27, 24, 16)
ReDim arrData(0 To UBound(varColumns), 0 To objFolder.Items.Count)
For i = LBound(arrData, 1) To UBound(arrData, 1)
arrData(i, 0) = objFolder.GetDetailsOf(objFolder.Items, varColumns(i))
Next i
fileCount = 0
For i = 0 To objFolder.Items.Count - 1
strFilename = objFolder.GetDetailsOf(objFolder.Items.Item(CLng(i)), 0)
If Right(strFilename, 4) = ".mp3" Or Right(strFilename, 4) = ".wav" Then
fileCount = fileCount + 1
For j = 0 To UBound(varColumns)
arrData(j, fileCount) = objFolder.GetDetailsOf(objFolder.Items.Item(CLng(i)), varColumns(j))
Next j
End If
Next i
Worksheets.Add
Columns("A:A").Select
Selection.NumberFormat = "@"
ActiveSheet.Name = "DB1"
Range("A1").Resize(UBound(arrData, 2) + 1, UBound(arrData, 1) + 1).Value = Application.Transpose(arrData)
Cells.Select
Selection.Columns.AutoFit
Range("A1").Select
End Sub