VBA study notes (4) - folders and files traverse the layer of VBA study notes (4) - one traverse folders and files

Description (2017.3.22):

1.

Copy the code
1 'to traverse the specified folder in the file 
 2' to traverse the specified folder, the file returned to the first layer (excluding folders) 
 . 3 Public Sub test1 () 
 . 4% K Dim 
 . 5 $ Dim filename 
 . 6 $ Dim path 
 . 7 = the ThisWorkbook path. path 
 . 8 'returns with the specified file name extension. If more than one *. * Files exist, 
 9 'function will return the file name under Condition finds. 
10 'when the second call Dir function, but without any parameters, the function returns the next *. * Files in the same directory 
. 11 filename = Dir (path & "\ *. *") 
12 is' the Range ( "A1 : AlO ") =" " 
13 is the Do the Until filename =" " 
14. 1 K = K + 
15 'Cells (K,. 1) filename = 
16 the Debug.Print (filename) 
. 17 = the Dir filename 
18 is Loop 
. 19 the Debug.Print (" complete ") 
20 End Sub 
21 '
23      Dim k%, path$, filename$
24      path = ThisWorkbook.path & "\2\"
25 '     dir第二个参数vbDirectory
26      filename = Dir(path, vbDirectory)
27      Do Until filename = ""
28         If Not filename Like "*.*" Then
29 '            k = k + 1
30 '            Cells(k, 1) = filename
31             Debug.Print (filename)
32         End If
33         filename = Dir
34     Loop
35 End Sub
Copy the code

Description (2017.3.22):

1.

Copy the code
1 'to traverse the specified folder in the file 
 2' to traverse the specified folder, the file returned to the first layer (excluding folders) 
 . 3 Public Sub test1 () 
 . 4% K Dim 
 . 5 $ Dim filename 
 . 6 $ Dim path 
 . 7 = the ThisWorkbook path. path 
 . 8 'returns with the specified file name extension. If more than one *. * Files exist, 
 9 'function will return the file name under Condition finds. 
10 'when the second call Dir function, but without any parameters, the function returns the next *. * Files in the same directory 
. 11 filename = Dir (path & "\ *. *") 
12 is' the Range ( "A1 : AlO ") =" " 
13 is the Do the Until filename =" " 
14. 1 K = K + 
15 'Cells (K,. 1) filename = 
16 the Debug.Print (filename) 
. 17 = the Dir filename 
18 is Loop 
. 19 the Debug.Print (" complete ") 
20 End Sub 
21 '
23      Dim k%, path$, filename$
24      path = ThisWorkbook.path & "\2\"
25 '     dir第二个参数vbDirectory
26      filename = Dir(path, vbDirectory)
27      Do Until filename = ""
28         If Not filename Like "*.*" Then
29 '            k = k + 1
30 '            Cells(k, 1) = filename
31             Debug.Print (filename)
32         End If
33         filename = Dir
34     Loop
35 End Sub
Copy the code

Guess you like

Origin www.cnblogs.com/medik/p/10989730.html