Count loop

Rafaelete

New Member
Joined
Feb 2, 2022
Messages
14
Office Version
  1. 2007
Platform
  1. Windows
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
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I am not clear what you are trying to do. Are you trying to count how many times each word occurs in the word document? and then generate a list of the words with the number of times each appeared in the document. If this is the case then this can be done quite easily using the dictionary object
 
Upvote 0
I am not clear what you are trying to do. Are you trying to count how many times each word occurs in the word document? and then generate a list of the words with the number of times each appeared in the document. If this is the case then this can be done quite easily using the dictionary object
I´m trying to count how many times the loop passes through each word document.
Once the code is finish with the first document, it does the following code and then starts the loop with the next word document.

Next tbBegin
End With


'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
Next

I want to create a list at the same time that shows how many changes it has done in each word document. I hope I´m making myself clear.
 
Upvote 0
I am not sure I do understand because what you are asking seems so simple: is this what you want??:
VBA Code:
'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.
wcount = 0
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)
wcount = wcount + 1
Next ColNo
RowOutputNo = RowOutputNo + 1
Next RowNo
End With
RowOutputNo = RowOutputNo
' ........ more code
next tbBegin
Debug.Print wcount
 
Upvote 0
I am not sure I do understand because what you are asking seems so simple: is this what you want??:
VBA Code:
'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.
wcount = 0
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)
wcount = wcount + 1
Next ColNo
RowOutputNo = RowOutputNo + 1
Next RowNo
End With
RowOutputNo = RowOutputNo
' ........ more code
next tbBegin
Debug.Print wcount
Sort of, I already fixed it anyways. It was close to that but I needed another statement that I couldn´t figure out.

Thanks anyways.
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,011
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top