In a Word document I have a number of tablea. Each Table has 2 columns and multiple rows.
In the first cell of each table (ie in the first column of the first row) other than the first two tables, I have the full name of a person (made up of a first name and a last name).
I would like to have a macro that would pull out the first name (from the full name) of every table in my word document (with the exception of the first two tables) and put it into an array of strings (called clientNames in my code). So after the macro runs my clientNames array should have the first names of all clients (having pulled them out from the first cell of every table in word document (with the exception of the first 2 tables.
The first two tables do not have any names in the first cell but have some different type of data, that is why I want to ignore them.
I have tried doing this with the code in the code window, but I keep getting either an error (subscript out of range) or my clientNames array does not get filled.
I would appreciate your help.
Private Sub cmdPullOutFirstNameNames()
Dim firstRow As range
Dim ClientFirstAndLasName As String
Dim FullName() As String
Dim FirstName As String
Dim i As Integer
Dim tableCount As Integer
tableCount = ActiveDocument.Tables.Count
tableCount = tableCount - 2
Dim clientNames() As Variant
i = 3
For i = 3 To ActiveDocument.Tables.Count
Set firstRow = ActiveDocument.Tables(i).Rows(1).range
ClientFirstAndLasName = firstRow.Cells(1).range.Text
ClientFirstAndLasName = Replace(ClientFirstAndLasName, Chr(7), "")
FullName = Split(ClientFirstAndLasName, " ")
FirstName = FullName(0)
' in the above line if just hard code the number of tables such as clientNames(20) the code then does not fill clientNames with the names.
clientNames(i) = FirstName
' if my code was working correctly I would expect something like below to happen
'clientNames(0) = "Catherine"
'clientNames(1) = "Peter"
'clientNames(2) = "Robert"
'clientNames(3) = "Smith"
' and so forth