Good afternoon,
I´m trying to extract information from multiple word documents that are in subfolders inside a folder. I have been able to extract information from the words that are inside the first folder, but I can´t find a way to make it work for the words that are inside the subfolders.
They are all inside the first folder:
Here I can extract the information from the docx document. But can´t access the words inside the folders 1034 and 1064.
The following code shows the part of the macro that extracts the information from the folder. I need it to work for the subfolders:
Dim FolderName As String
Dim FileName As String
Dim NewWordFile As New Word.Application
Dim NewDoc As New Word.Document
Dim wdDoc As Object
Dim wdFileName As Variant
Dim TableNo As Integer 'table number in Word
Dim iRow As Long 'row index in Excel
Dim iCol As Integer 'column index in Excel
FolderName = "C:\Users\rriveragarrido\Desktop\Proyectos\Proyecto solaris (endesa) (PROPIO)\prueba macros\ZZZ\try\"
FileName = Dir(FolderName & "*.docx")
'Comineza el loop para que corra en cada una de las narrativas.
Do While FileName <> ""
Set wdDoc = GetObject(FolderName & FileName)
With wdDoc
'Este check sirve para identificar si no hay ninguna tabla en el word. En caso de ser así, te devuelve un mensaje indicándotelo.
TableNo = wdDoc.Tables.Count
If TableNo = 0 Then
MsgBox "This document contains no tables"
End If
'FROM HERE IT STARTS TO EXTRACT THE INFORMATION FROM ALL THE WORDS LOCATED IN THE FOLDER.
'Nombra la fila en la que va a empezar el código:
RowOutputNo = Range("O1").End(xlDown).Row
ColOutputNo = 15
'Pasa por cada una de las tablas que hay en la narrativa. En cada narrativa hay varias tablas, por lo que es importante determinar en cada narrativa cuantas hay.
For tbBegin = 1 To TableNo
'Copia la información de cada una de las celdas de word a excel.
With .Tables(tbBegin)
For RowNo = 1 To .Rows.Count
For ColNo = 2 To .Columns.Count
Cells(RowOutputNo, ColOutputNo) = WorksheetFunction.Clean(.cell(RowNo, ColNo).Range.Text)
Next ColNo
RowOutputNo = RowOutputNo + 1
Next RowNo
End With
RowOutputNo = RowOutputNo
Next tbBegin
End With
FileName = Dir()
'Sort the table to select next narrative
Range("Table1").Sort Key1:=Range("O1"), Order1:=xlDescending, Header:=xlYes
Range("Table1[[#Headers],[Responsable Actividad]]").Select
Selection.End(xlDown).Select
ActiveCell.Offset(rowOffset:=1, columnOffset:=0).Activate
Loop
Thank you in advanced.
I´m trying to extract information from multiple word documents that are in subfolders inside a folder. I have been able to extract information from the words that are inside the first folder, but I can´t find a way to make it work for the words that are inside the subfolders.
They are all inside the first folder:
Here I can extract the information from the docx document. But can´t access the words inside the folders 1034 and 1064.
The following code shows the part of the macro that extracts the information from the folder. I need it to work for the subfolders:
Dim FolderName As String
Dim FileName As String
Dim NewWordFile As New Word.Application
Dim NewDoc As New Word.Document
Dim wdDoc As Object
Dim wdFileName As Variant
Dim TableNo As Integer 'table number in Word
Dim iRow As Long 'row index in Excel
Dim iCol As Integer 'column index in Excel
FolderName = "C:\Users\rriveragarrido\Desktop\Proyectos\Proyecto solaris (endesa) (PROPIO)\prueba macros\ZZZ\try\"
FileName = Dir(FolderName & "*.docx")
'Comineza el loop para que corra en cada una de las narrativas.
Do While FileName <> ""
Set wdDoc = GetObject(FolderName & FileName)
With wdDoc
'Este check sirve para identificar si no hay ninguna tabla en el word. En caso de ser así, te devuelve un mensaje indicándotelo.
TableNo = wdDoc.Tables.Count
If TableNo = 0 Then
MsgBox "This document contains no tables"
End If
'FROM HERE IT STARTS TO EXTRACT THE INFORMATION FROM ALL THE WORDS LOCATED IN THE FOLDER.
'Nombra la fila en la que va a empezar el código:
RowOutputNo = Range("O1").End(xlDown).Row
ColOutputNo = 15
'Pasa por cada una de las tablas que hay en la narrativa. En cada narrativa hay varias tablas, por lo que es importante determinar en cada narrativa cuantas hay.
For tbBegin = 1 To TableNo
'Copia la información de cada una de las celdas de word a excel.
With .Tables(tbBegin)
For RowNo = 1 To .Rows.Count
For ColNo = 2 To .Columns.Count
Cells(RowOutputNo, ColOutputNo) = WorksheetFunction.Clean(.cell(RowNo, ColNo).Range.Text)
Next ColNo
RowOutputNo = RowOutputNo + 1
Next RowNo
End With
RowOutputNo = RowOutputNo
Next tbBegin
End With
FileName = Dir()
'Sort the table to select next narrative
Range("Table1").Sort Key1:=Range("O1"), Order1:=xlDescending, Header:=xlYes
Range("Table1[[#Headers],[Responsable Actividad]]").Select
Selection.End(xlDown).Select
ActiveCell.Offset(rowOffset:=1, columnOffset:=0).Activate
Loop
Thank you in advanced.