K
KR
I am working with some documents that have embedded tables. I need to merge
these documents but keep track of what information came from which document.
Only the 4th cell in each row (not including header rows) will be
copied/merged to a new document.
The preferred (existing) method is to add a UserID (each workbook creator's
initials, which is the same as the first two digits of the filename) to the
fourth cell in every row of the target tables (except the first row, which
is headers). Each document will have a number of tables. In addition to the
initials, I also need to add the content of the first cell in the same row,
since I will not be copying that over individually. For example:
Filename: MS_042706.doc
(any table, any row 2+)
col1 col2 col3 col4
Yes blah blah lots of text
++ blah blah lots of text
should end up as:
col1 col2 col3 col4
Yes blah blah lots of text (MSYes)
++ blah blah lots of text (MS++)
Here is my code, but it doesn't seem to like the way I refer to TempTable
(method or data member not found). Since I haven't got it working yet feel
free to comment on any other problems you see with the code if any jump out
at you...
Many thanks in advance,
Keith
Sub Add_Examiner_Info()
Dim TempTable As Table
Dim i As Integer
Dim CellValue
Dim RatingValue
UserId = InputBox("Enter Creator ID for active document", "Enter ID")
If Len(UserId) > 0 Then
With ActiveDocument
For Each TempTable In .Tables
With TempTable
If TempTable.Rows.Count > 2 Then
For i = 2 To TempTable.Rows.Count
CellValue = Trim(.TempTable.Rows(i).Cells(4).Text) '<<
stops here
RatingValue = Trim(.TempTable.Rows(i).Cells(4).Text)
.TempTable.Rows(i).Cells(4).Text = CellValue & _
" (" & UserId & RatingValue & ")"
Next i
End If
End With
Next
End With
Else
MsgBox "UserID cannot be blank" & Chr(13) & Chr(13) & "Please try
again", , "No ID entered"
End If
End Sub
these documents but keep track of what information came from which document.
Only the 4th cell in each row (not including header rows) will be
copied/merged to a new document.
The preferred (existing) method is to add a UserID (each workbook creator's
initials, which is the same as the first two digits of the filename) to the
fourth cell in every row of the target tables (except the first row, which
is headers). Each document will have a number of tables. In addition to the
initials, I also need to add the content of the first cell in the same row,
since I will not be copying that over individually. For example:
Filename: MS_042706.doc
(any table, any row 2+)
col1 col2 col3 col4
Yes blah blah lots of text
++ blah blah lots of text
should end up as:
col1 col2 col3 col4
Yes blah blah lots of text (MSYes)
++ blah blah lots of text (MS++)
Here is my code, but it doesn't seem to like the way I refer to TempTable
(method or data member not found). Since I haven't got it working yet feel
free to comment on any other problems you see with the code if any jump out
at you...
Many thanks in advance,
Keith
Sub Add_Examiner_Info()
Dim TempTable As Table
Dim i As Integer
Dim CellValue
Dim RatingValue
UserId = InputBox("Enter Creator ID for active document", "Enter ID")
If Len(UserId) > 0 Then
With ActiveDocument
For Each TempTable In .Tables
With TempTable
If TempTable.Rows.Count > 2 Then
For i = 2 To TempTable.Rows.Count
CellValue = Trim(.TempTable.Rows(i).Cells(4).Text) '<<
stops here
RatingValue = Trim(.TempTable.Rows(i).Cells(4).Text)
.TempTable.Rows(i).Cells(4).Text = CellValue & _
" (" & UserId & RatingValue & ")"
Next i
End If
End With
Next
End With
Else
MsgBox "UserID cannot be blank" & Chr(13) & Chr(13) & "Please try
again", , "No ID entered"
End If
End Sub