Good afternoon,
I have created a loop that goes through different words. I want to know the number of times the code goes through in each word and place it inside a list in excel.
I have tried different methods but I´m unable to find a method to solve it. Any help will be greatly appreciate it. Thanks!
This is the part of the code that shows the loop:
Dim FolderName As String
Dim filename As String
Dim NewWordFile As New Word.Application
Dim NewDoc As New Word.Document
Dim i As Integer
Dim WordFiles() As String
FolderName = "C:\Users\rriveragarrido\Desktop\Proyectos\Proyecto solaris (endesa) (PROPIO)\prueba macros\ZZZ\try\"
If Not LoopAllSubFolders(WordFiles, FolderName, "*.docx") Then
MsgBox "No files found."
Exit Sub
End If
'Comineza el loop para que corra en cada una de las narrativas.
For i = 0 To UBound(WordFiles)
Set wdDoc = GetObject(WordFiles(i))
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
I have created a loop that goes through different words. I want to know the number of times the code goes through in each word and place it inside a list in excel.
I have tried different methods but I´m unable to find a method to solve it. Any help will be greatly appreciate it. Thanks!
This is the part of the code that shows the loop:
Dim FolderName As String
Dim filename As String
Dim NewWordFile As New Word.Application
Dim NewDoc As New Word.Document
Dim i As Integer
Dim WordFiles() As String
FolderName = "C:\Users\rriveragarrido\Desktop\Proyectos\Proyecto solaris (endesa) (PROPIO)\prueba macros\ZZZ\try\"
If Not LoopAllSubFolders(WordFiles, FolderName, "*.docx") Then
MsgBox "No files found."
Exit Sub
End If
'Comineza el loop para que corra en cada una de las narrativas.
For i = 0 To UBound(WordFiles)
Set wdDoc = GetObject(WordFiles(i))
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