jvbeaupre
11-17-2014, 04:24 PM
In a Powerpoint (Office 2011) macro, I am trying to list all the files of a certain type in a folder.
The subroutine I'm using to get the next file uses the statement "file = Dir()". Dir() is returning "", and not the next file.
Dir is however returning a valid 1st file and CurDir is OK.
Does anyone has a work around.
The code I'm using is the following:
Sub GetFileList(Extn, Path, nList, List())
If Path = "" Then Path = CurDir
Debug.Print Path
fileID = 0 'Will still work if Mac files have the windoz extension
Sym = ":"
If LCase(Extn) = "wmf" Then fileID = MacID("WMF ")
If LCase(Extn) = "jpg" Then fileID = MacID("JPEG")
If LCase(Extn) = "gif" Then fileID = MacID("GIFf")
If LCase(Extn) = "pct" Then fileID = MacID("PICT")
If LCase(Extn) = "bmp" Then fileID = MacID("BMP ")
file = Dir(Path & Sym, fileID)
Debug.Print "file", file, fileID
nList = 0
Do While file <> "" ' Start the loop.
If LCase(Right(file, 3)) = LCase(Extn) Then
nList = nList + 1
ReDim Preserve List(1 To nList)
List(nList) = Path & Sym & file
End If
Debug.Print nList, List(nList)
file = Dir() ' Get next entry.
Debug.Print "file2", file
Loop
If nList > 0 Then Call Sort(nList, List)
End Sub
The subroutine I'm using to get the next file uses the statement "file = Dir()". Dir() is returning "", and not the next file.
Dir is however returning a valid 1st file and CurDir is OK.
Does anyone has a work around.
The code I'm using is the following:
Sub GetFileList(Extn, Path, nList, List())
If Path = "" Then Path = CurDir
Debug.Print Path
fileID = 0 'Will still work if Mac files have the windoz extension
Sym = ":"
If LCase(Extn) = "wmf" Then fileID = MacID("WMF ")
If LCase(Extn) = "jpg" Then fileID = MacID("JPEG")
If LCase(Extn) = "gif" Then fileID = MacID("GIFf")
If LCase(Extn) = "pct" Then fileID = MacID("PICT")
If LCase(Extn) = "bmp" Then fileID = MacID("BMP ")
file = Dir(Path & Sym, fileID)
Debug.Print "file", file, fileID
nList = 0
Do While file <> "" ' Start the loop.
If LCase(Right(file, 3)) = LCase(Extn) Then
nList = nList + 1
ReDim Preserve List(1 To nList)
List(nList) = Path & Sym & file
End If
Debug.Print nList, List(nList)
file = Dir() ' Get next entry.
Debug.Print "file2", file
Loop
If nList > 0 Then Call Sort(nList, List)
End Sub