Hi
I'm trying to write a Macro in excel that will parse files in directories and subdirectories.
I started by trying to get a list of directories and subdirectories but the following code ends with error.
MyPath = "c:\stat\"
Application.DisplayAlerts = True
MToProcess = Dir(MyPath, vbDirectory)' Retrieve the first entry.
Do While MToProcess <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MToProcess <> "." And MToProcess <> ".." Then
' Use bitwise comparison to make it is a directory.
If (GetAttr(MyPath & MToProcess) And vbDirectory) = vbDirectory Then
PNamePath = MyPath + MToProcess + "\"
PToProcess = Dir(PNamePath, vbDirectory)
End If ' it represents a directory.
End If
MToProcess = Dir ' Get next entry.
Loop
It looks like the line "PToProcess = Dir(PNamePath, vbDirectory)" messes up all the structure and I end with an error.
Any ideas how to fix this, I will need to nest about 5 subdirectories and files inside.
I'm trying to write a Macro in excel that will parse files in directories and subdirectories.
I started by trying to get a list of directories and subdirectories but the following code ends with error.
MyPath = "c:\stat\"
Application.DisplayAlerts = True
MToProcess = Dir(MyPath, vbDirectory)' Retrieve the first entry.
Do While MToProcess <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MToProcess <> "." And MToProcess <> ".." Then
' Use bitwise comparison to make it is a directory.
If (GetAttr(MyPath & MToProcess) And vbDirectory) = vbDirectory Then
PNamePath = MyPath + MToProcess + "\"
PToProcess = Dir(PNamePath, vbDirectory)
End If ' it represents a directory.
End If
MToProcess = Dir ' Get next entry.
Loop
It looks like the line "PToProcess = Dir(PNamePath, vbDirectory)" messes up all the structure and I end with an error.
Any ideas how to fix this, I will need to nest about 5 subdirectories and files inside.