- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to get the filenames of some drawings in a folder. I've got the following code, but it's not working. I get a file count from the line "filecount = objFiles.Count", so it's recognizing "objFiles" as the collection of files in the folder, but everything after that simply does nothing. Oddly, I can change the "If" statement from "<>" to "=", and it still reads the "Then" statement in both cases. However, the FileName is blank. What am I doing wrong?
Dim objFile As FileDialogs
Set objFile = New FileDialogs
objFile.Title = strFolderName
objFile.StartInDir = "C:\Documents and Settings"
strFolderName = objFile.ShowOpen
strFolderName = Left$(strFolderName, InStrRev(strFolderName, "\") - 1)
MsgBox strFolderName
Dim fso As Object
Dim objFiles As Object
Dim filecount As Integer
Dim dwgfilenum As Integer
Dim poo As Variant
'Create objects to get a count of files in the directory
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objFiles = fso.GetFolder(strFolderName).Files
'If Err.Number <> 0 Then
filecount = objFiles.Count
For dwgfilenum = 1 To filecount
If Right((objFiles.Item(dwgfilenum).FullFileName), 3) <> "dwg" Then
poo = objFiles.Item(dwgfilenum).FullFileName
MsgBox poo
'filecount = filecount - 1
End If
Next
MsgBox filecount
Solved! Go to Solution.