
Macro DIR () List carpeta y dir () list Subcarpetas error
Publicado por Agnes (2 intervenciones) el 28/06/2017 19:44:02
Hola a todos, tengo hecha una macro que lista carpetas de 1 ruta y después con los datos de la 1 lista saco 2 lista de carpetas. Pero se ve al listar la 2 ruta se guarda en los datos de la 1, nose como hacer que cada una tenga su lista.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
mySourcePath es la ruta princpical de la 1 lista
Sub ListMyFiles(mySourcePath)
' List the files and directories within "C:\".
mySourcePath = mySourcePath & "\"
Dim fList As String
Dim fLists As String
Dim fName As String
Dim fNames As String
Dim numero As String
numero = 0
iRow = 2
For inicios = 0 To Total
fName = Dir(mySourcePath, vbDirectory)
' The variable fName now contains the name of the first file or directory within "C:\".
If InStr(fNames, ".") > 0 Then
numero = Left(fNames, InStr(fNames, ".") - 1)
ElseIf InStr(fNames, "..") > 0 Then
numero = Left(fNames, InStr(fNames, "..") - 1)
End If
If numero = "" Then
inicios = 0
End If
Do While fName <> ""
' Store the current file or directory name in the string fList.
fList = fList & vbNewLine & fName
datos = Range("A" & iRow).Value
aux = 0
MsgBox "Ruta 1.1: " & fList
MsgBox "Datos: " & datos
If datos <> fName Then
fName = Dir()
ElseIf datos = fName Then
'la otra ruta modifica para que lista otras carpetas
rutas = mySourcePath & fName & "\ASUNTOS\"
fNames = Dir(rutas, vbDirectory)
Do While fNames <> ""
'fLists = fLists & vbNewLine & fNames
' Get the next file or directory within "C:\".
If InStr(fNames, ".") > 0 Then
numero = Left(fNames, InStr(fNames, ".") - 1)
ElseIf InStr(fNames, "-") > 0 Then
numero = Left(fNames, InStr(fNames, "-") - 1)
ElseIf InStr(fNames, "_") > 0 Then
numero = Left(fNames, InStr(fNames, "_") - 1)
End If
If numero = "" Then
fNames = Dir()
End If
If numero <> "" Then
iRows = 2
For inicio = 0 To Total
dato = Range("B" & iRows).Value
If dato = numero Then
Range("F" & iRows).Value = numero
ruta = fNames + numero
ActiveSheet.Hyperlinks.Add Anchor:=Cells(iRows, "E"), Address:=ruta, TextToDisplay:=numero
End If
If dato <> numero Then
End If
If dato = "" Then
End If
iRows = iRows + 1
Next inicio
fNames = Dir()
End If
Loop
iRow = iRow + 1
End If
Loop
fName = fName
fName = Dir()
iRow = iRow + 1
Next inicios
End Sub
Valora esta pregunta


0