Hello Gregory,
I have two word documents, one document used content control (Test_www.docx) and the other document (Test daily.docx) has a table.
I was physically copying each cell from one table into the content controlled document. Now, thanks to some help I am using a macro to copy the data over, however whenever I save the document as a .docx I get a error:
The file "........docx cannot be opened because there are problems with the contents".
Details:
Unspecified error"
Location: Part: /word/document.xml, Line 2, Column: 275153
I traced down the error (basically by commenting each line out 1 by 1) to the following line of code:
Code:
tgtTable.Cell(i, 5).Range.ContentControls(1).Range.Text = strDesc
The description field contains, letters, numbers, symbols (° ' ") and so forth so declaring this field as a sting should be good. I tried to edit this line of code and to find a solution online but nothing seems to work.
Can you tell me what ContentControls(1) <- the (1) is for? From what I gather the '1' refers to the first ContentControl in that cell.
Things I tired (one at a time of course) >
-Dim strDesc as Variant
-Changed tgtTable.Cell(i, 5).Range.ContentControls(1).Range.Text to .... .ContentControls(2), .ContentControls(3), .ContentControls(4), .ContentControls(5), .ContentControls(i) etc.
-Updated Word
Does anyone have any suggestions on how to fix this error?
Jordan
Source code
Code:
Sub aTest()
Dim srcDoc As Document, tgtDoc As Document
Dim srcTable As Table, tgtTable As Table
Dim i As Integer, strTime As String, strDesc As String
Set srcDoc = Documents("Test daily (1).docx")
Set tgtDoc = Documents("Test www.docx")
Set srcTable = srcDoc.Tables(1)
Set tgtTable = tgtDoc.Tables(1)
For i = 2 To srcTable.Rows.Count
strTime = srcTable.Cell(i, 1).Range.Text
strTime = Left(strTime, Len(strTime) - 2)
strDesc = srcTable.Cell(i, 2).Range.Text
strDesc = Left(strDesc, Len(strDesc) - 2)
tgtTable.Cell(i, 1).Range.ContentControls(1).Range.Text = strTime
tgtTable.Cell(i, 5).Range.ContentControls(1).Range.Text = strDesc
Next
End Sub