PDA

View Full Version : Dir Function Anomoly



gmaxey
02-14-2015, 10:43 AM
I have a large project that uses the Dir function to process Word documents .doc/.docx/.docm extension files. It works perfectly on my PC regardless of the root folder I use to process. A user has reported that it is not working for him (as written) when he uses one of his installed hard drives as the root folder.

When he attempted to use the addin with .docx format files in a folder "D:\Test" it didn't work. If he uses C:\Test or E:\Test then it does work.


I created a folder "D:\Test" and put in it a .doc format file an a docx format file.
Here is a much abbreviated bit of code we have used for trouble shooting. When I run the code both the .doc and .docx files are recognized and processed. When he ran the code none of his .docx files where processed!

When I changed FileType = "*.doc*" then his files in his D:\Test where then processed. Very weird. Why would the code as originally written work with all of my root drives, work with his C: and E: root drives but not his D: root drive?? Thanks


Sub Troubleshooter()
Dim strPath As String, strFileName As String
Dim lngCount As Long, lngFileCount As Long, lngCounter As Long

Dim FileType As String
strPath = "D:\Test\"
FileType = "*.doc"
'FileType = "*.doc*"
MsgBox strPath & " Do you see this message 1 and is the path returned the same as the path you entered?"
strFileName = Dir$(strPath & FileType)
While Len(strFileName) <> 0
MsgBox strFileName
strFileName = Dir$()
Wend
lbl_Exit:
Exit Sub
End Sub