Visual Basic para Aplicaciones - Adaptar macro a excel 2010

Life is soft - evento anual de software empresarial
 
Vista:

Adaptar macro a excel 2010

Publicado por cArLos (1 intervención) el 30/01/2015 20:30:52
Hola foro,
necesitaria adaptar esta macro a excel 2010. (filesearch dejo de aplicarse en Excel 2010) en concreto la sentencia Foundfiles:

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
Private Sub Busca_File_old()
Dim NmArch As String
Dim Contcolum As Long
Dim Nfiles As Long
Dim i As Long
Dim fs As Object
 
Set fs = Application.FileSearch
 
With fs
    .LookIn = ThisWorkbook.Path 'Establece ruta de busqueda el directorio donde ubicamos la aplicacion
 
    .Filename = "*.*.XLS"
 If .Execute > 0 Then
        MsgBox "Se han encontrado " & .FoundFiles.Count & _
            " archivos."
        Nfiles = .FoundFiles.Count
 
        For i = 1 To Nfiles  'Contador numero de archivos
            NmArch = Dir(.FoundFiles(i), 9) 'Variable almacena nombre
            Contcolum = ThisWorkbook.Sheets(1).Range("H1").Value
            ThisWorkbook.Sheets(1).Range("AF" & Contcolum).Value = NmArch
            Call ImportarData(NmArch, Contcolum)
        Next i
 
 
  Else
  MsgBox "No se ha encontrado ningun archivo " & NmArch & Chr(13) & " en el directorio de la aplicacion"
  End If
End With
 
 
Application.DisplayAlerts = True
Application.StatusBar = False
Set fs = Nothing
 
End sub

La macro busca una serie de archivos de forma secuencial y extrae una serie de datos. ( abriendolos y cerrandolos despues en la aplicacion ImportarData)
Gracias de antemano
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Adaptar macro a excel 2010

Publicado por The_Best (1 intervención) el 31/01/2015 18:35:40
Hi friend, try this little shut

sure its the most suitable code for you:

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
Sub Busca_File() 'Just for work with Excel 2010
 
    Dim Coll_Docs As New Collection
    Dim Search_path, Search_Filter, NmArch As String
    Dim NmFile As String
    Dim Contcolum As Long
    Dim i As Long
 
    Search_path = ThisWorkbook.Path & "\"
    Search_Filter = "?.*.xls"
    Set Coll_Docs = Nothing
 
    NmFile = Dir(Search_path & "\" & Search_Filter)
 
    Do Until NmFile = ""            ' Coleccion nombre archivo
        Coll_Docs.Add Item:=NmFile
        NmFile = Dir
    Loop
 
    MsgBox "Se han encontrado " & Coll_Docs.Count & " archivos"
 
    For i = Coll_Docs.Count To 1 Step -1              '
        'NmArch = Search_path & "\" & Coll_Docs(i)
        NmArch = Coll_Docs(i)
        Contcolum = ThisWorkbook.Sheets(1).Range("H1").Value
        ThisWorkbook.Sheets(1).Range("AF" & Contcolum).Value = NmArch
        Call ImportarData(NmArch, Contcolum)
   Next
Application.DisplayAlerts = True
Application.StatusBar = False
End Sub

Good luck
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar