![]() |
|
|||||||
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 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
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help Please: New VBA user trying to use a macro to split Mail Merge documents. Two Run-Time Error | zipit189 | Word VBA | 7 | 03-18-2015 01:13 PM |
| Macro to copy cell info to multiple documents | Patrick Innes | Word VBA | 2 | 02-18-2015 08:38 PM |
| Want to change Macro to copy and paste data to new sheet | Vortex69 | Excel Programming | 0 | 12-23-2014 09:53 PM |
Word macro: copy from different tables into one table
|
adisl | Word VBA | 4 | 03-25-2014 02:40 AM |
Run-time Error 5174: Open Word Documents from Excel
|
tinfanide | Excel Programming | 3 | 10-01-2013 07:35 AM |